2024-10-05 11:08:43 发布
网友
我正在使用Selenium和Python(Chorme驱动程序)在文本框中编写一些内容,但是有很多文本框,我需要它来更快地填充它们。我用一系列
driver.find_element_by_xpath("//input[@class='string required' and @id='order_billing_name']").send_keys("test.com")
但是写10-11这些命令需要很多时间。有没有办法加快速度?在
您可以尝试使用javascript设置值:
orderBillingName = driver.find_element_by_id("order_billing_name") driver.execute_script("arguments[0].value=arguments[1];", orderBillingName, "mytext")
您可以使用javascript直接设置:
许多字段的示例:
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)
您可以尝试使用javascript设置值:
您可以使用javascript直接设置:
^{pr2}$许多字段的示例:
相关问题 更多 >
编程相关推荐