1

I'm trying to click on a button "Administration" inside an iframe but I'm getting this error:

selenium.common.exceptions.TimeoutException: Message:

Python code I am using:

main = driver.find_element_by_xpath("//div[@class='main absolute']")
main.click()
driver.switch_to.frame("tab_Welcome")
button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.wah-global-ask-banner-item div.wah-global-ask-banner-item-title.wah-global-ask-banner-item-title-paa")))
button.click()

HTML:

enter image description here

1
  • Welcome to Stack Overflow! Please read why a screenshot of code is a bad idea. Paste the code and properly format it instead. Commented Sep 25, 2019 at 14:59

4 Answers 4

3

To click() on the element with text as Administration as the the desired elements are within an <iframe> so you have to:

  • Induce WebDriverWait for the desired 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:

    • CSS_SELECTOR:

      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.iframe-content#tab_Welcome")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.wah-global-ask-banner-item-title.wah-global-ask-banner-item-title-paa"))).click()
      
    • XPATH:

      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@class='iframe-content' and @id='tab_Welcome']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='wah-global-ask-banner-item-title wah-global-ask-banner-item-title-paa' and text()='Administration']"))).click()
      
    • 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
      

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

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

Comments

2

Induce WebDriverWait and frame_to_be_available_and_switch_to_it() Induce WebDriverWait and element_to_be_clickable() and Following XPATH.

main = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='main absolute']")))
main.click()
WebDriverWait(driver,20).until(EC.frame_to_be_available_and_switch_to_it((By.NAME,"frame_Welcome")))
button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[text()='Administration']")))
button.click()

4 Comments

It didn't work, still got the timeout error, it wasn't able to click on 'main absolute'
@Luiz : Sorry my mistake.Missed the parenthesis.Try now.
well clicking on main worked, but i'm still getting the same error for the administration button
@Luiz : Can it possible to share url?
0

It looks like you're switching to the iframe using its ID, but you need to switch to it by name.

So instead of driver.switch_to.frame("tab_Welcome")

You should try driver.switch_to.frame("frame_Welcome")

Hope this helps.

2 Comments

There is an existing ExpectedCondition that handles waiting for a frame, EC.frame_to_be_available_and_switch_to_it(). See KunduK's answer.
@Luiz It's possible the issue is with the CSS selector itself which is causing the timeout, even if you successfully switched to the iframe. It looks like @KunduK has implemented a correct XPath selector that you can use: //div[text()='Administration']
0
def find_all_iframes(driver):
    iframes = driver.find_elements_by_xpath("//iframe")
    for index, iframe in enumerate(iframes):
        # Your sweet business logic applied to iframe goes here.
        driver.switch_to.frame(index)
        find_all_iframes(driver)
        driver.switch_to.parent_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.