'Python move_to_element().click() is not pressing a right element visible on the screen or returns the error. A trial code is included

I try to interact with the elements (button at this scenario) inside Disqus iframe on this webpage:

This is my trial code:

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time


path_to_chromedriver = r"c:\users\tv21\source\repos\chromedriver.exe"

driver = webdriver.Chrome(executable_path=path_to_chromedriver)

driver.maximize_window()

url = "https://www.postoj.sk/91472/po-navsteve-kina-si-precitajte-aj-kniznu-predlohu"

driver.get(url)

time.sleep(5)
   
button_to_close = driver.execute_script("return document.querySelector('body').querySelector('div.grv-dialog-host').shadowRoot.querySelector('div').querySelector('div.buttons-wrapper').querySelector('button.sub-dialog-btn.block_btn')")

ac = ActionChains(driver)
 
ac.move_to_element(button_to_close).click().perform()

open_discussion = driver.find_element_by_class_name('article-disqus-wrapper')

driver.execute_script("arguments[0].setAttribute('style','display: block;')", open_discussion)

disqus_thread = driver.find_element_by_id("disqus_thread")

iframe_element = disqus_thread.find_element_by_tag_name("iframe")

driver.switch_to.frame(iframe_element)

time.sleep(1)

button_to_load_more = driver.find_element_by_partial_link_text("Nahraj viac komentárov")

ac = ActionChains(driver)
     
ac.move_to_element(button_to_load_more).click().perform()

The issue is the last command:

ac.move_to_element(button_to_load_more).click().perform()

which shows an error: "move target out of bounds"

I tried instead:

button_to_load_more.click()

and

driver.execute_script("arguments[0].click();", button_to_load_more)

which both work completely fine as the alternatives and I can click the button.

However, I try to understand the reason for being out of bounds when using move_to_element(). I get exactly the same error always when I want to hover over any elements inside Disqus iframe too.

Can anyone help me to fix it or explain to me how to fix it?



Solution 1:[1]

First one dint worked because of the known issue in selenium,i guess you are using 3.4 hence facing this.(But it should work after trying newer version of selenium)

Some of the useful links fyr

Selenium MoveTargetOutOfBoundsException even after scrolling to element

https://github.com/SeleniumHQ/selenium/issues/4148

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mk7644