Home > database >  Locate search box but could not enter value with Selenium
Locate search box but could not enter value with Selenium

Time:01-08

I have the following HTML structure and I am trying to use Selenium to enter a text into search box. I clould locate search box could not enter a text. It is HTML structure and code I have written:

<input tabindex="0" data-testid="search-input" data-analytics-link="GlobalNav|Txt|||||Search Bar"  value="">

enter image description here

driver.find_element(By.XPATH, "//input[@data-testid='search-input']/parent::label").send_keys(text)

Please help me understand what is going wrong here.

It could find the element but could not enter text.

CodePudding user response:

You are trying to enter the text into a parent element (a label element) of the input element, rather than the input element itself.

To enter text into the input element, you should use the .send_keys() method on the input element directly.

driver.find_element(By.XPATH, "//input[@data-testid='search-input']").send_keys(text)
  • Related