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

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
ctaggart
  • 166
  • 1
  • 10
  • 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. – ctaggart Dec 11 '20 at 15:43

3 Answers3

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:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
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()
PDHide
  • 18,113
  • 2
  • 31
  • 46
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)
Parolla
  • 408
  • 2
  • 6