我试图通过使用selenium的python脚本自动从网站下载数据,但我得到了以下错误:
"WebDriverException: Message: TypeError: rect is undefined".代码试用:
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)现在,我定义了要单击的复选框,并尝试单击它:
temp=driver.find_element_by_xpath('//input[@value="TEMP"]')
action = action_chains.ActionChains(driver)
action.move_to_element(temp)
action.click()
action.perform()我已经在网上搜索了2个小时,但没有任何结果。因此,欢迎任何想法!
提前谢谢你!
发布于 2018-05-11 02:27:25
有两个元素与该定位器匹配。第一个是不可见的,所以我假设你想点击第二个。
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()发布于 2018-05-11 00:26:35
此错误消息...
WebDriverException: Message: TypeError: rect is undefined...implies当您尝试与所需的WebElement交互时,它可能没有定义client rects。
根据,主要问题是您试图与之交互的所需元素,即invoke click() is present is the not visible,即not displayed。
原因
最可能的原因和解决方案如下:
当您尝试单击元素时,可能无法交互所需的元素,因为某些 / Ajax调用可能仍在进行active.
解决方案
temp = wait.until(EC.element_to_be_clickable((By.XPATH,“//input@value=”temp“”)) action.perform()
temp = driver.find_element_by_xpath("//input@value="TEMP"") driver.execute_script("arguments.scrollIntoView();",temp);action.perform() =action_chains.ActionChains(驱动程序) action.move_to_element(temp) action.click()
发布于 2021-02-28 23:38:51
我也有这个问题。但是,当我像下面这样编写代码时,我没有任何问题。
temp=driver.find_element_by_xpath('//input[@value="TEMP"]')
action_chains.ActionChains(driver).move_to_element(temp).perform()
action_chains.ActionChains(driver).click(temp).perform()https://stackoverflow.com/questions/50276598
复制相似问题