[英]selenium.common.exceptions.WebDriverException: Message: unknown error: 'script' must be a string while using execute_script() through Selenium Python
[英]selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable while inserting value using Selenium and Python
我正在尝试将值插入位于网页中的文本框中。
文本框出现在网页的底部,并且该代码找不到该元素。 我应该进行两次检查 ,以查看Chrome中的表格值(首次显示所有HTML /父HTML),这表明我们存在多个层次,需要深入研究。
我尝试插入如下所示的字符串。
driver.find_element_by_id("arid1005").send_keys("TESTING")
和
elem = driver.find_element_by_id("arid1005")
driver.execute_script('arguments[0].value = "TESTING";',elem)
我也尝试过通过类名,CSS,Xpath查找元素,但最终得到
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
当我检查2次时,下表将突出显示。
<table class="SearchBarInput" width="100%">
<tbody>
<tr><td width="">
<textarea style="width:99%;height:21px;" class="sr" cols="" wrap="off" rows="1" id="arid1005"></textarea></td>
</tr>
</tbody>
</table>
有人可以告诉我我在这里想念的东西吗? 抱歉,是否已经有人问过这个问题,但到目前为止我找不到任何相关问题。
所需元素的id属性看起来很动态,因此要对元素进行click()
就必须为element_to_be_clickable()
诱导WebDriverWait ,并且可以使用以下任一解决方案:
使用CSS_SELECTOR
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "table.SearchBarInput>tbody>tr>td>textarea"))).send_keys("TESTING")
使用XPATH
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//table[@class='SearchBarInput']/tbody/tr/td/textarea"))).send_keys("TESTING")
注意 :您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
参考资料:您可以在以下位置找到一些相关的讨论:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.