WebDriverException: Message: TypeError: rect is undefined

Mathador picture Mathador · May 10, 2018 · Viewed 14.7k times · Source

I am trying to automate the download of data from a website with a python script using selenium but I get the following error:

"WebDriverException: Message: TypeError: rect is undefined".

Code trial:

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)

Now I define the check-box I want to click and I try to click on it:

temp=driver.find_element_by_xpath('//input[@value="TEMP"]')
action = action_chains.ActionChains(driver)

action.move_to_element(temp)
action.click()
action.perform()

I already searched 2 hours on the net without any success. Any idea is therefore welcome!

Thanks a lot in advance!

Answer

JeffC picture JeffC · May 10, 2018

There are two elements that match that locator. The first one is not visible so I'm assuming you want to click on the second.

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()