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!

2
  • 1
    Please read the posting guidelines 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? Commented Aug 7, 2023 at 5:02
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Commented Aug 7, 2023 at 10:01

1 Answer 1

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
    
Sign up to request clarification or add additional context in comments.

Comments

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.