2

Is there something faster I can use to fill forms since finding id's and sending info via .send_keys takes like 10 seconds for 7 fields. I'm using this currently but its way to slow for what I need it to do, thanks for any help.

driver.find_element_by_xpath("//*[@id='order_billing_name']").send_keys("John Doe")
driver.find_element_by_xpath("//*[@id='order_email']").send_keys("[email protected]")
driver.find_element_by_xpath("//*[@id='order_tel']").send_keys("012-345-6789")
driver.find_element_by_xpath("//*[@id='bo']").send_keys("439 N Fairfax Ave")
driver.find_element_by_xpath("//*[@id='order_billing_city']").send_keys("Los Angeles")
driver.find_element_by_xpath("//*[@id='order_billing_zip']").send_keys("90036")
driver.find_element_by_xpath("//*[@id='nnaerb']").send_keys("1111222233334444")
2
  • Is the delay in sending the keys, or in finding the elements? Try temporarily removing the .send_keys(...) from these calls and see if that makes a noticeable difference. Commented May 6, 2018 at 5:29
  • @JohnGordon how can I test that? I'm able to grab item I need and size in under 2 seconds when finding elements however the checkout page just takes long. Even when sendkey is typing it's very slow Commented May 6, 2018 at 6:21

2 Answers 2

3

I had this problem a few hours ago. Instead of send_keys() use

driver.execute_script("document.getElementById('idName').setAttribute('value','text_to_put');
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, it worked perfect and very fast. I tried to do the same method for drop down menu select but that didn't work as well haha. Any suggestions?
I'm not sure but I would assume you would click it first then try to .click the right option, have not tried it though
Just to clarify - this is for finding an element faster, not for making send_keys faster (when much input is used). Also, does this method support XPATH finding?
0

To fill the form fields quicker you can use induce WebDriverWait for the element_to_be_clickable() and then use execute_script() as follows:

  • Using CSS_SELECTOR:

    text_to_insert = "John Doe"
    driver.execute_script("arguments[0].value = '" + text_to_insert + "';", WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#order_billing_name"))))
    
  • Using XPATH:

    text_to_insert = "John Doe"
    driver.execute_script("arguments[0].value = '" + text_to_insert + "';", WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='order_billing_name']"))))
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

References

You can find a couple of relevant detailed discussions in:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.