0

enter image description here

I'm unable to locate the frame - tabFrame from the attached screenshot, whereas I was able to locate outlookFrame. I used:

driver.switch_to.frame('outlookFrame') 

But when I use:

driver.switch_to.frame('tabFrame')

It doesn't work.

Shawn Hemelstrand
  • 2,676
  • 4
  • 17
  • 30
user1776130
  • 35
  • 1
  • 1
  • 4

1 Answers1

0

As the desired elements is within nested <iframe> elements so you have to:

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

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

  • Induce WebDriverWait for the desired element to be clickable.

  • You can use either of the following locator strategies:

    • Using CSS_SELECTOR:

      driver.get("http://web_page")
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"outlookFrame_cssSelector")))
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[name='tabFrame']")))
      
    • Using XPATH:

      driver.get("http://web_page")
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"outlookFrame_xpath")))
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@name='tabFrame']")))
      
  • 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