0

So I'm trying to write a test for a webpage which has some elements within an iframe. I've been able to successfully run the test using webdriver.Firefox() without any problems but if I switch it over to webdriver.Chrome() I get a timeout exception on the following lines of code:

 self.driver.switch_to.frame(0)
 self.activity_status = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, '#overview > div.details.w-66 > div > div.duration-and-status > span.status.stat_incomplete#')))

It'd be great to get a solution to this as I'm all out of ideas.

Thanks for your help.

edit, partial html for the page:

<iframe id="iframe_course_details" allowfullscreen="" src="../Course/Details.aspx?HidePageNav=true&amp;IsInIframe=true"></iframe>

Close Edit (Inactive) Edit

        <span id="ctl00_cph_main_content_area_ucCourseDetails_spn_favourite" class="favourite button tooltipstered" style="display: none;">Favourite</span>
        <span id="ctl00_cph_main_content_area_ucCourseDetails_spn_basket_dull" class="add-to-basket button delete tooltipstered" style="display: none;">Enrolled (Remove From Enrolments)</span>
        <span id="ctl00_cph_main_content_area_ucCourseDetails_spn_basket" class="add-to-basket button tooltipstered">Add to Enrolments</span>
        <span id="ctl00_cph_main_content_area_ucCourseDetails_spn_print" class="print button tooltipstered">Print</span>
    </div>
    <section id="overview" style="opacity: 1;">
        <div id="fullname" class="fullname w-100" style="display: none;">

        </div>
        <div class="image w-33" style="cursor: pointer;">
        <div style="background-image:url(/App_Themes/MainTheme-responsive/Images/Course/webcast.jpg);"></div></div>
        <div class="details w-66">
            <div class="inner">
                <h2>testing activity</h2>
                <div class="star-rating-num-ratings">
                    <div class="star-rating">
                        <span></span><span></span><span></span><span></span><span></span>
                    </div>
                    <span class="num-of-ratings">0 Ratings</span>
                </div>
                <div class="duration-and-status">
                    <span class="duration">
                        <label>
                            Duration:
                        </label>
                        <span>0</span>
                    </span>
                    <span class="status stat_incomplete">Started</span>
                </div>          

Edit 2:

So we've managed to find a solution to this and its even more confusing than the original problem

WebDriverWait(self.driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.ID, 'iframe_course_details')))
    time.sleep(0)
    self.activity_status = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="overview"]/div[3]/div/div[2]/span[2]')))

I'd be really curious to hear some theories on why this works, it times out without the 'time.sleep(0).

2 Answers2

0

If you reference the iframe directly rather then an integer that will work between Firefox/Chrome.

self.driver.switch_to.frame(driver.find_element_by_name("iframe"))

You can find the iframe element any way you wish e.g by css/xpath etc

Cl0ud-l3ss
  • 175
  • 2
  • 10
0

As the the desired element is within an <iframe> so to invoke click() on the element you have to:

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

    • Code Block:

      # as per your comment assuming -> there is only one frame on the page
      WebDriverWait(self.driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.TAG_NAME,"iframe")))
      self.element = self.activity_status = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, '#overview > div.details.w-66 > div > div.duration-and-status > span.status.stat_incomplete#')))
      
    • 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 relevant detailed discussion in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352