0

I am trying to send text to an input field, but selenium is not able to find the element.

element = WebDriverWait(b, 10).until(EC.presence_of_element_located((By.XPATH, '/html/body/table/tbody/tr[1]/td/form/div/table/tbody/tr[2]/td/table[2]/tbody/tr/td[4]/table/tbody/tr/td[1]/input')))
element.send_keys("Customer Care", Keys.ENTER)

I've tried using the XPATH, the full XPATH and the ID to locate it, but it keeps giving me an error that indicates that it cannot find the element selenium.common.exceptions.TimeoutException

A snippet of the HTML element

<input class="iceInpTxt testBox" id="headerForm:jumpto" maxlength="40" name="headerForm:jumpto" onblur="setFocus('');iceSubmitPartial(form, this, event);" onfocus="setFocus(this.id);" onkeyup="iceSubmit(form,this,event);" onmousedown="this.focus();" type="text" value="">

2
  • Share HTML in text format or provide the URL Commented Jan 23, 2020 at 20:44
  • I know its not a solution but you can use chrome.google.com/webstore/detail/selenium-ide/… to capture test steps and probably even see why its timing out Commented Jan 23, 2020 at 20:45

3 Answers 3

1

Element has ID, use it as locator. Check if element is inside a iframe:

wait = WebDriverWait(b, 10)
element = wait.until(EC.element_to_be_clickable((By.ID, 'headerForm:jumpto')))
element.send_keys("Customer Care", Keys.ENTER)

How to switch to iframe:

wait = WebDriverWait(b, 10)

wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe_locator")))

element = wait.until(EC.element_to_be_clickable((By.ID, 'headerForm:jumpto')))
element.send_keys("Customer Care", Keys.ENTER)

# How to go back to default content
b.switch_to.default_content()
Sign up to request clarification or add additional context in comments.

2 Comments

It is in an iframe. What can I do about it?
Using code in the answer how to switch to iframe. Share html of the iframe
0

it is a good idea to check whether or not you installed and imported selenium or other necessary packages. Use pip to check your version and see if there is a bug online. Please let me know what python version you are using. It is likely the XPATH you provided was incorrect or maybe try increasing the amount of time in the 2nd parameter of WebDriverWait(1st,2nd). It would be much more helpful if you had a link to this html page so I could check your XPATH. If you'd like further help, please provide your html page.

Edit: This is something that needs to be reproduced so that it can be checked. If you have tried the above, I am unable to help unless I see the html document. You should remove all sensitive information before sharing it. The other elements of your code seem to be correct.

3 Comments

I am using python version Python 3.7.6. I am not able to provide the HTML page because that would involve me giving you my login credentials.
@SisqoBaker, At this point I recommend that you test each element in your XPATH. Use EC.presence_of_element_located((By.XPATH, thePath) , first test that the html is there(to check if it's in the right format, I don't know how you accessed your html). Then you do body/table etc until you get to the one where it stops working.
@SisqoBaker I don't see any harm in providing the HTML and in the coarse of providing the text based relevant HTML you don't need to provide your credentials anyway. Rather without the HTML, neither you would get any canonical answer nor the contributors can test the locators they want to suggest you. So providing the HTML is a win-win situation for both.
0

If your usecase involves invoking click() or send_keys() while inducing WebDriverWait instead of presence_of_element_located() you need to use the expected_conditions as element_to_be_clickable() as follows:

So effectively, you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(b, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.iceInpTxt.testBox[id^='headerForm'][name$='jumpto']"))).send_keys("Customer Care", Keys.ENTER)
    
  • Using XPATH:

    WebDriverWait(b, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='iceInpTxt testBox' and @id='headerForm:jumpto'][@name='headerForm:jumpto']"))).send_keys("Customer Care", Keys.ENTER)
    

References

You can find a couple of detailed discussion about the different expected_conditions in:

1 Comment

@SisqoBaker Checkout the updated answer and let me know the status.

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.