2

I'm learning Selenium with Python, and attempting to write happy path flow for a website. Where I get stuck is a part of the flow where an iframe is automatically launched after clicking through a pop-up window. I've tried several different methods, but am unable to locate the frame, or wait for it appear. Either it's not found or times out.

WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.ID, 'continue-  reservation'))).click()


# cvv2 form
WebDriverWait(driver, 5).until(EC.frame_to_be_available_and_switch_to_it((By.ID, 'cvv_iframe')))

Error:

WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.ID, 'cvv_iframe')))
File "/Users/anutter/venv/lib/python3.7/site-packages/selenium/webdriver/support/wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:

HTML is as follows:

                <div id="cpstaging" class="emptystage">
                    <div class="fixed h-v-centered new-preload" style="display: none;"><span class="fa fa-spinner f-50 f-grn fa-pulse"></span></div>
                </div>
                <div id="cvv-box" class="pad-30-lr">
                    <div id="enter-cvv-title" class="blk mar-20-b f-18 border-b pad-10-b">Enter CVV Code</div>
                    <iframe src="https://qa-hotels.ecbsn.com/cvv?oauth_token=u7q99%2Fe8I%2BkUrkLMr4dGR2t4gmcDbVtr&amp;type=visa&amp;src=web-desktop" id="cvv_iframe" name="cvv_iframe" width="430" height="160" frameborder="0" seamless="seamless" scrolling="no" sandbox="allow-same-origin allow-scripts allow-popups allow-forms"></iframe>
                </div>
            </div>
        </div>
    </div>
anutter
  • 366
  • 2
  • 17
  • Please read why a [screenshot of HTML or code or error is a bad idea](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). Consider updating the Question with formatted text based relevant HTML, code trials and error stack trace. – undetected Selenium Nov 29 '18 at 20:31
  • Thanks for the tip, added html as a code block. – anutter Nov 29 '18 at 22:04

1 Answers1

0

As per the HTML you have shared to access the elements within the <iframe> you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it using either of the Locator Strategies:

    • Using ID:

      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"cvv_iframe")))
      
    • Using NAME:

      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.NAME,"cvv_iframe")))
      
    • Using CSS_SELECTOR:

      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#cvv_iframe[name='cvv_iframe']")))
      
    • Using XPATH:

      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@id='cvv_iframe' and @name='cvv_iframe']")))
      
  • Note: As per your code trials the ID of the <iframe> isn't cvv-iframe but cvv_iframe

Here you can find a relevant discussion on Ways to deal with #document under iframe

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • D'oh, that was super obvious. Unfortunately, after correcting the iframe name I'm still getting a timeout exception. Maybe I'm not using the correct ID? I've tried several others ID's, as well as using CSS selector, and nothing has been successful. – anutter Nov 29 '18 at 20:29
  • @anutter Your comment doesn't help me either. Sorry, the answer didn't help you to solve your problem but how am I going to improve my post with that feedback? – undetected Selenium Nov 29 '18 at 20:32
  • I updated the description with the error, as well as the more of the HTML for the page, not sure what else I can add to make my issue clearer? – anutter Nov 29 '18 at 20:36