1

I am using safari and selenium on python, I want to make a python selenium program that clicks a 'confirm' button in an iframe, but it gives me an error or it doesn't work (the button and the iframe are in the viewport)

basically anyway I try, if the button is clicked with 'action chains' it gives me the same error (selenium.common.exceptions.MoveTargetOutOfBoundsException: Message:) , or if the button is clicked normally it doesn't have any result (doesn't work)

Html - iframe

<iframe title="Confirm-box" scrolling="no" class="bottom" data-name="bottom">
</iframe>

Html - Button

<button type="submit" class="btn btn-submit" name="submitBtn">
    Confirm
</button>

The iframe

iframe2 = driver.find_elements_by_tag_name('iframe')[1]

Scroll to the button

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(2)
driver.switch_to.frame(iframe2)

double click the button

actionChains = ActionChains(driver)
element = driver.find_element_by_xpath("//button[contains(text(),'Confirm')]")
actionChains.double_click(element).perform()

Expected output:

button is clicked

Error (action-chains):

selenium.common.exceptions.MoveTargetOutOfBoundsException: Message:

1 Answers1

0

You can't click directly into an iframe element, first, you need to use a special command in selenium switchTo, that allow you to change the context you can switch between (iframes, windows, and alerts).

I don't know the syntax in python but it should be something like this:

driver.switchTo().iframe('iframe');

You can see the official documentation here: https://www.seleniumhq.org/docs/03_webdriver.jsp#moving-between-windows-and-frames

Juan Henao
  • 220
  • 1
  • 3
  • 14