2

I've used Selenium for a number projects without problems. This one, however, no dice.

I'm trying to automate a check out process, and sometimes there is a prompt to re-input information. The window has a javascript popup (I think), and, while I can select the <div id="app"> portion without any problems, I CANNOT get find the iframe and focus on it.

So, this works:

driver.find_elements_by_id('app')

But, nothing works to recognize the frame and switch to it. For example, none these work:

driver.find_element_by_id()
driver.find_element_by_name()
driver.find_element_by_xpath()

And, I assume that because I can't find and switch to the iframe.

Help?

webpage code

1
  • Everyone, thank you for the quick and (I anticipate) helpful answers. I won't be able to test this out until later tonight or tomorrow. I'll keep you posted. Commented Dec 11, 2020 at 15:43

3 Answers 3

1

The element with the text as E-Mail Login is within an <iframe> so you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.

  • You can use either of the following Locator Strategies:

    • Using CSS_SELECTOR:

      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.zoid-visible[title='ec_payment'][name^='__zoid__ec__payment']")))
      
    • Using XPATH:

      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@class='zoid-visible' and @title='ec_payment'][starts-with(@name, '__zoid__ec__payment')]")))
      
  • Note : You have to add the following imports :

     from selenium.webdriver.support.ui import WebDriverWait
     from selenium.webdriver.common.by import By
     from selenium.webdriver.support import expected_conditions as EC
    

Reference

You can find a couple of relevant discussions in:

Sign up to request clarification or add additional context in comments.

1 Comment

DebanjanB, thank you! This got me through it!
0
driver.switch_to.frame(iframe_elem)

or

driver.switch_to_frame(iframe_id)

in your case you can use :

driver.switch_to.frame(driver.find_element_by_tag_name("iframe"));

to switch back to main use:

driver.switch_to_default_content()

Comments

0

Try this code to switch to frame

frame = driver.find_element_by_xpath('//div[starts-with(@id, "zoid-ec-payment")]/iframe')
driver.switch_to.frame(frame)

Comments

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.