[英]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.