[英]How to use execute_script in python and selenium to select a value from drop down
I have a form whose elements return elementnotinteractable exception when I use selenium operations like click() and sen_keys. 我有一种形式,当我使用诸如click()和sen_keys之类的硒操作时,其元素返回elementnotinteractable异常。
I used execute_script to interact with elements and it works fine. 我使用execute_script与元素进行交互,并且效果很好。 However, I am unable to perform a select from dropdown operation.
但是,我无法执行下拉菜单中的选择。 I like an execute_script equivalent of following statement -
我喜欢相当于以下语句的execute_script-
path = ".//div[@id='web_service_dlg']//select[@name='tenancy']/option[@value='Customer Tenancy']"
self.browser.find_element_by_xpath(path).click()
Above statement fails with the exception elementnotinteractable I am trying to solve the problem by doing the following - 上面的语句失败,异常元素不可互操作我试图通过执行以下操作来解决问题 -
element = self.browser.find_element_by_xpath(".//div[@id='web_service_dlg']//select[@name='tenancy']/option[@value='Customer Tenancy']")
self.browser.execute_script("return arguments[0].scrollIntoView(true);", element)
self.browser.execute_script("return arguments[0].removeAttribute('onkeypress');", element)
self.browser.execute_script("return arguments[0].click();", element)
Above statement does not give me any error, but it is not selecting the element I want. 上面的语句没有给我任何错误,但是它没有选择我想要的元素。 What am I doing wrong?
我究竟做错了什么?
用户selected=true
。
self.browser.execute_script("return arguments[0].selected=true;", element)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.