0

I'm having trouble locating element <input class='search-text'...> and would like to place the text 'hello' into the text box.

Trying to locate the input class='search-text'

My webdriver code is the following

driver.find_element(By.XPATH, "//ul[@class='filter-panel']//li[@class='filter-selection']//filter-selector//div[@class=filter-component]//div//div[@class='search-box-wrapper']/input[@class='search-text']").send_keys("hello")

That results in:

Exception has occurred: NoSuchElementException
Message: no such element: Unable to locate element: {"method":"xpath","selector":"//ul[@class='filter-panel']//li[@class='filter-selection']//filter-selector//div[@class=filter-component]//div//div[@class='search-box-wrapper']/input[@class='search-text']"}

I was hoping the word "hello" would be placed in the Search... box.

HTML snapshot of the Search... input box:

I'm trying to locate the Search... input box

Does anyone have any ideas? Thanks!

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Please read the [posting guidelines](/help/how-to-ask) which explicitly and in **bold and ALL CAPS** tell you not to post images of text (which includes not posting links to images of text). Put _the text_ in your post. On a different note: why use xpath when you're working with web pages? Why not just run a queryselect inside the document you loaded? – Mike 'Pomax' Kamermans Aug 07 '23 at 05:02
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Aug 07 '23 at 10:01

1 Answers1

0

Given the html:

html

the desired element is a dynamic element.


Solution

Ideally to send a character sequence to the element you need 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.search-text[aria-label='Enter text for search by keyword']"))).send_keys("yummybagels")
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='search-text' and @aria-label='Enter text for search by keyword']"))).send_keys("yummybagels")
    
  • 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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352