Divya Mani
Divya Mani

Reputation: 313

NoSuchElementException in python selenium

I am trying to give input to the inputbox.i have tried using find_by_d/name and xpath also.But still getting

File "C:\Users\1024983\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element 'value': value})['value'] File "C:\Users\1024983\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Users\1024983\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="combobox-1023-inputEl"]"}

By using name

  your_input = driver.find_element_by_name("combobox-1023-inputEl")
  your_input.clear()
  your_input.send_keys("Coke")
  driver.find_element_by_name("combobox-1023-inputEl").send_keys(Keys.ENTER)
  time.sleep(2)

By using id

driver.find_element(By.ID, "combobox-1023-inputEl").click()
driver.find_element(By.ID, "combobox-1023-inputEl").send_keys("Coke")

input box

<input id="combobox-1023-inputEl" type="text" role="combobox" class="x-form-field x-form-required-field x-form-text" autocomplete="off" name="combobox-1023-inputEl" style="width: 100%;">

Upvotes: 0

Views: 533

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193358

The desired element is a dynamic element so to send a character sequence with in the element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.x-form-field.x-form-required-field.x-form-text[id^='combobox'][name$='inputEl']"))).send_keys("Coke")
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='x-form-field x-form-required-field x-form-text' and starts-with(@id,'combobox')][contains(@name,'inputEl')]"))).send_keys("Coke")
    
  • 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
    

Reference

You can find a detailed relevant discussion in:

Upvotes: 0

Related Questions