Mat*_*dor 8 firefox selenium python-3.x selenium-webdriver geckodriver
我正在尝试使用 selenium 从带有 python 脚本的网站自动下载数据,但出现以下错误:
"WebDriverException: Message: TypeError: rect is undefined".
Run Code Online (Sandbox Code Playgroud)
代码试用:
from selenium import webdriver
from selenium.webdriver.common import action_chains
driver = webdriver.Firefox()
url="https://www.hlnug.de/?id=9231&view=messwerte&detail=download&station=609"
driver.get(url)
Run Code Online (Sandbox Code Playgroud)
现在我定义了要单击的复选框并尝试单击它:
temp=driver.find_element_by_xpath('//input[@value="TEMP"]')
action = action_chains.ActionChains(driver)
action.move_to_element(temp)
action.click()
action.perform()
Run Code Online (Sandbox Code Playgroud)
我已经在网上搜索了 2 个小时,但没有任何成功。因此,欢迎任何想法!
非常感谢!
这个错误信息...
WebDriverException: Message: TypeError: rect is undefined
Run Code Online (Sandbox Code Playgroud)
...意味着当您尝试与之交互时,所需的WebElement可能没有定义客户端矩形。
根据TypeError: rect is undefined, when using Selenium Actions and element is not displayed.主要问题,尽管您尝试与之交互的所需元素 [即调用click()]存在于HTML DOM 中,但不可见,即未显示。
最可能的原因和解决方法如下:
诱导WebDriverWait使元素可点击,如下所示:
temp = wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@value="TEMP"]")))
action = action_chains.ActionChains(driver)
action.move_to_element(temp)
action.click()
action.perform()
Run Code Online (Sandbox Code Playgroud)使用execute_script()方法滚动元素查看如下:
temp = driver.find_element_by_xpath("//input[@value="TEMP"]")
driver.execute_script("arguments[0].scrollIntoView();", temp);
action = action_chains.ActionChains(driver)
action.move_to_element(temp)
action.click()
action.perform()
Run Code Online (Sandbox Code Playgroud)有两个元素与该定位符匹配。第一个不可见,所以我假设您要单击第二个。
temp = driver.find_elements_by_xpath('//input[@value="TEMP"]')[1] # get the second element in collection
action = action_chains.ActionChains(driver)
action.move_to_element(temp)
action.click()
action.perform()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16823 次 |
| 最近记录: |