Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click on iframe element using Python selenium

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.

like image 640
mohsen solhnia Avatar asked Oct 27 '25 21:10

mohsen solhnia


1 Answers

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()
like image 96
Richard Avatar answered Oct 29 '25 15:10

Richard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!