4

How can I click the red button here from Host A (in this example jsfiddle.net) using selenium python? (javascript limitation policy error do not let me do it). Also I do not want to click directly Red Button. Thanks.

el =driver.find_element_by_xpath("/html/body/div[2]/input")
webdriver.ActionChains(driver).move_to_element(el).click(el).perform()

iframe that keeps red button:

<iframe src="http://www.myhostb.blogfa.com/" width="500" height="300">
</iframe>

Important note: imaging that jsfiddle.net is Host A.

1 Answer 1

10

You need to use switch_to_frame()

driver.switch_to_frame("result")
driver.switch_to_frame(driver.find_element_by_css_selector("body>iframe"))
driver.find_element_by_css_selector("input.ex2").click()

Once you're done in the iframe, you can switch back to the top frame using:

driver.switch_to_default_content()
Sign up to request clarification or add additional context in comments.

4 Comments

@mohsensolhnia The example above should work with the HTML example you provided. As for the "same domain policy", I have no idea what that refers to, and I don't appreciate you yelling at me, particularly when I don't see "same domain policy" in your original question.
i got error Message: unknown error: Error is not a function
@BudiMulyo If you have a question, I would highly recommend that you create a new one, with code examples, the HTML you are trying to access, and the complete error message, in the Selenium tag. I would gladly take a look and see if I can help you with it.
@Richard thanks for reply, but it was solved using wait.until(EC.frame_to_be_available_and_switch_to_it(chrome.find_element_by_xpath("//iframe[@id='mainframe']")))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.