0

How to pass value in input field i.e. Search box? I tried using cssSelector as:

element = driver.findElement(By.cssSelector("input[placeholder='Search for restaurants and food']"));  

and using className as well.

Snapshot of the element:

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

To send a character sequence to the Search field within the Swiggy website you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following locator strategies:

  • cssSelector:

    new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input[placeholder='Search for restaurants and food']"))).sendKeys("Pizza");
    
  • xpath:

    new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@placeholder='Search for restaurants and food']"))).sendKeys("Pizza");
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352