使用Selenium和python在textBox中快速编写 [英] Fast writing in a textBox with selenium and python
本文介绍了使用Selenium和python在textBox中快速编写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Selenium和Python(Chorme驱动程序)在文本框中编写内容,但是有很多文本框,我需要它来更快地填充它们.我使用
I'm using Selenium with Python (Chorme driver) to write something in a text box but there are a lot of textboxes and I need it to fill them faster. I use a sequences of
driver.find_element_by_xpath("//input[@class='string required' and @id='order_billing_name']").send_keys("test.com")
命令,但是编写10-11这些命令会花费很多时间.有办法加快速度吗?
commands but to write 10-11 these takes a lot of time. Is there a way to fast it up?
推荐答案
您可以尝试使用javascript设置值:
You can try to set values using javascript:
orderBillingName = driver.find_element_by_id("order_billing_name")
driver.execute_script("arguments[0].value=arguments[1];", orderBillingName, "mytext")
您可以直接使用javascript进行所有设置:
You can set all directly with javascript:
driver.execute_script("document.querySelector('#order_billing_name').value='mytext';"\
"document.querySelector('.order_number_class').value='12323';"\
"document.querySelector('input#anotherinputid').value='anything';")
很多字段的示例:
fields = {
"input#order_billing_name": "some text",
".order_number_class" : "some text",
"css selector" : "some text",
"css selector" : "some text",
"css selector" : "some text"
}
js = ""
for selector, value in fields.items():
js = js + "document.querySelector('" + selector + "').value='"+ value +"';"
driver.execute_script(js)
这篇关于使用Selenium和python在textBox中快速编写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文