Alexis
Alexis

Reputation: 89

Selenium WebDriverWait keeps throwing a TimeoutException

I am using Selenium to login to as follows:

driver.switch_to.default_content()
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.NAME,'email'))).send_keys("[email protected]")

but I keep getting an error:

TimeoutException: Message:

I have also tried:

WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@id='email']"))).send_keys("[email protected]")

Here is the source HTML code I am accessing:

<div id="signup-form">
    <div class="logo"></div>
    <h1 data-i18n="signin">Sign in</h1>
    <div class="panels-wrapper">
        <div class="panels">
            <div class="panel step-1">
                <input name="email" type="text" id="email" required="" maxlength="100">
                <label for="email" data-i18n="email">Email</label>

Appreciate any guidance to fix this.

Upvotes: 0

Views: 571

Answers (2)

undetected Selenium
undetected Selenium

Reputation: 193148

There are a couple of things you need to take care.

In case the element is within a / , without the relevant HTML it would be tough to construct a canonical answer. However, as per the HTML you have shared, I don't see the presence of any <frame> / <iframe>.


Generally, to send a character sequence within the element you need to use WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#email[name='email']"))).send_keys("[email protected]")
    
  • XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='email' and @name='email']"))).send_keys("[email protected]")
    

You can find a relevant discussion in How to click on a element through Selenium Python


In case the element is within a 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:

    • Using CSS_SELECTOR:

      driver.get('site_url')
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe_cssSelector")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#email[name='email']"))).send_keys("[email protected]")
      
    • Using XPATH:

      driver.get('site_url')
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"iframe_xpath")))
      WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='email' and @name='email']"))).send_keys("[email protected]")
      
    • 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
      

      You can find a relevant discussion in Unable to type within username field within ProtonMail signup page using Selenium and Python


Reference

You can find a couple of relevant discussions in:

Upvotes: 1

UnknownBeast
UnknownBeast

Reputation: 979

Email is not a frame. The condition you are using is used for frame( iframe tag ) but here you are dealing with input tag. So I suggest you to check either the visibility of that element or presence of that element based on your requirement.

Upvotes: 1

Related Questions