Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to slow down the speed of send_keys action in a selenium script using python?

I am currently creating a selenium script in python. I need to enter something in a text box using send_keys function. It is doing that correctly as of now. However, for an observation for I need to slow down the speed at which send_keys populates the text field. Is there a way I can do that? Also, is there any alternate to send_keys in selenium? Thanks&Regards karan

like image 736
karan juneja Avatar asked Mar 19 '17 19:03

karan juneja


People also ask

How do I slow down selenium WebDriver execution in Python?

If you are looking to slow down or pause your execution, press F8 (if you are using chrome).

Is Selenium slower than requests?

Using Requests generally results in faster and more concise code, while using Selenium makes development faster on Javascript heavy sites.

Why is selenium so slow python?

The Selenium WebDriver scripts are very slow because they run through the browser. There are multiple things that can improve the Selenium WebDriver scripts' speed: use fast selectors. use fewer locators.


1 Answers

You could insert a pause after each character is sent. For example, if your code looked like this:

el = driver.find_element_by_id("element-id")
el.send_keys("text to enter")

You could replace it with:

el = driver.find_element_by_id("element-id")
text = "text to enter"
for character in text:
    el.send_keys(character)
    time.sleep(0.3) # pause for 0.3 seconds
like image 63
Mark Lapierre Avatar answered Oct 05 '22 02:10

Mark Lapierre