I have quite a unique goal and I'm having a hard time to have my python code working. Inside a big selenium application, I'm trying simply to check if an element located on a specific position in the browser corresponds to an element. For example, if you look at the test website: https://learn.letskodeit.com/p/practice there's one element (link) labeled "Open Tab" and its coordinates on the browser are: x = 588, y = 576. This is the code I'm using to confirm in that position I have that element:
target_elem = driver.find_element_by_id("opentab")
print("target elem actual location: {}".format(target_elem.location))
time.sleep(1)
zero_elem = driver.find_element_by_tag_name('body')
x_body_offset = zero_elem.location["x"]
y_body_offset = zero_elem.location["y"]
print("Body coordinates: {}, {}".format(x_body_offset, y_body_offset))
x = 588
y = 576
actions = ActionChains(driver)
actions.move_to_element_with_offset(driver.find_element_by_tag_name('body'), -x_body_offset, -y_body_offset).click()
actions.move_by_offset( x, y ).send_keys(Keys.ESCAPE).perform()
elem_found = driver.switch_to.active_element
print(elem_found.text)
when I print elem_found.text I don't get "Open Tab". however, if inside the action chain, right before perform(), I add click(), the code above does click on the "Open Tab" link. Hence my question: can we simply select the element by knowing its exact position in the browser? I totally understand getting element by location is not really the best way to get element but on my end, I do really need to be able to confirm if an element in position X,Y corresponds to something I expect to find in that location.