0

I am trying to send_keys to this input :

<input id="textfield-1017-inputEl" data-ref="inputEl" type="text" size="1" name="search" placeholder="Find Bunker.." aria-hidden="false" aria-disabled="false" role="textbox" aria-invalid="false" aria-readonly="false" aria-describedby="textfield-1017-ariaStatusEl" aria-required="false" class="searchfield x-form-text x-form-text-default  x-form-empty-field x-form-empty-field-default" autocomplete="off" data-componentid="textfield-1017">

but I am always getting this error :

Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="textfield-1017-inputEl"]"} (Session info: chrome=80.0.3987.163)

I am using selenium in python , and this is the code I am using :

find_my_input = browser.find_element_by_id('textfield-1017-inputEl')
BalticOY
  • 3
  • 2

2 Answers2

0

Make sure you wait for the element to be loaded using the explicit wait as shown below.

Imports needed:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

change the code to the below.

find_my_input = WebDriverWait(browser,30).until(EC.presence_of_element_located((By.ID,"textfield-1017-inputEl")))

If element is present in the iframe then you have to switch to the iframe first and then access the element.

driver.switch_to.frame('id/name goes here')
find_my_input = WebDriverWait(browser,30).until(EC.presence_of_element_located((By.ID,"textfield-1017-inputEl")))
supputuri
  • 13,644
  • 2
  • 21
  • 39
  • I have received the following message : TimeoutException: Message: – BalticOY Apr 12 '20 at 04:33
  • I even changed that 30s to 120s, but it's not working. – BalticOY Apr 12 '20 at 04:38
  • Do you see the element on the page? If, yes then the element might be present in an iframe. check if the element is pointing to the root html element or any iframe html using `//input[@id='textfield-1017-inputEl']/ancestor::html` in chrome devtools as shown [here](https://stackoverflow.com/questions/55870609/is-there-a-way-to-learn-xpath-without-using-firebug-or-xpath-as-firefox-is-not-s/55870909#55870909) – supputuri Apr 12 '20 at 04:39
  • it's is not an iframe, i got the following result : – BalticOY Apr 12 '20 at 04:58
  • whats the parent of ``? – supputuri Apr 12 '20 at 05:03
  • the parrent is : ` – BalticOY Apr 12 '20 at 05:15
  • What should I do in case of there are many parents of this iframe ( 3 divs and 2 iframes) ? – BalticOY Apr 12 '20 at 05:24
0

Try below solution:

wait = WebDriverWait(driver, 30)
iframe= wait.until(EC.presence_of_element_located((By.ID, "ext-gen1099")))
driver.switch_to.frame(iframe)

element= WebDriverWait(driver, 30).until(
                EC.element_to_be_clickable((By.ID, "textfield-1017-inputEl")))

Note : please add below imports to your solution

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
SeleniumUser
  • 4,065
  • 2
  • 7
  • 30
  • It was a nested iframe, I used your solution and it worked. Thank you! – BalticOY Apr 12 '20 at 21:55
  • Glad to hear that , would you kind enough to [accept](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) answer and hit upvote button from your end. – SeleniumUser Apr 12 '20 at 21:55