简体   繁体   中英

How to pass value in search field within Swiggy website using Selenium WebDriver and Java

How to pass value in input field ie 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:

在此处输入图像描述

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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM