Reputation: 59
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")
Upvotes: 2
Views: 4172
Reputation: 193058
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
You can find a couple of relevant detailed discussions in:
Upvotes: 0
Reputation: 339
I had this problem a few hours ago. Instead of send_keys()
use
driver.execute_script("document.getElementById('idName').setAttribute('value','text_to_put');
Upvotes: 3