I wonder how I can replace send_keys in Python selenium.

Asked 2 years ago, Updated 2 years ago, 41 views

Text input via send_keys in python selenium is too slow. You're repeating the task of importing from a text file and typing about 3000 bytes at a time You need a quick way to copy and paste from text.

When I searched through Google, I heard that if you use the language used in JavaScript like this, you can input it quickly.

driver.execute_script("document.getElementsByName('query')[0].value=\'" + id + "\'")

As I progressed, it was similar or a little faster.

I'm using send_keys, but it's too slow. I can change this part like above How do I switch to a faster way to replace send_keys?

python selenium javascript

2022-09-22 18:37

1 Answers

The Selenium method is to give up performance and resource efficiency and use it.

For performance, just use requests and pass the variable to post.

In other words, you don't have to put a value in the input object on the screen with send_keys, but you can use the requests module to send the string from the text file to the address you want to send to post. This is the most efficient structure.


2022-09-22 18:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.