How to Handle Autosuggestion Dropdown in Selenium Using Java ?

.
How to Handle Autosuggestion Dropdown in Selenium WebDriver?


How To Select Value From Auto Suggestion Dropdown?

Selenium Code:

public class AutoSuggestiveDropdown {


public static void main(String[] args) throws InterruptedException {

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","C:\\Users\\Admin\\Downloads\\chromedriver-win64 (1)\\chromedriver-win64\\chromedriver.exe");

WebDriver driver = new ChromeDriver();

driver.get("https://rahulshettyacademy.com/dropdownsPractise/");

WebElement auts= driver.findElement(By.id("autosuggest"));

auts.click();

auts.sendKeys("Ind");

Thread.sleep(2000);

List<WebElement> opt= driver.findElements(By.cssSelector(" li[class='ui-menu-item'] a"));

for (WebElement option : opt)

{

if (option.getText().equalsIgnoreCase("India"))

{

option.click();

break;

}

else {

System.out.println("Not availble in the Autosuggestion Dropdown");

}

}


How to Verify that the selected value is correct or not from the Autosuggestion Dropdown?

Selenium Code:


public class AutoSuggestiveDropdown {


public static void main(String[] args) throws InterruptedException {

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","C:\\Users\\Admin\\Downloads\\chromedriver-win64 (1)\\chromedriver-win64\\chromedriver.exe");

WebDriver driver = new ChromeDriver();

driver.get("https://rahulshettyacademy.com/dropdownsPractise/");

WebElement auts= driver.findElement(By.id("autosuggest"));

auts.click();

auts.sendKeys("Ind");

Thread.sleep(2000);

List<WebElement> opt= driver.findElements(By.cssSelector(" li[class='ui-menu-item'] a"));

for (WebElement option : opt)

{

if (option.getText().equalsIgnoreCase("India"))

{

System.out.println("Selected Correct Value From the Autosuggestion Dropdown");

option.click();

break;

}

}

}


}



Hope!!! The Above Tutorial on How to handle auto-suggestion Dropdown in Selenium is helpful for you...

Team,
QA acharya

How to Handle Auto Suggestion Dropdown in Selenium 

 

Post a Comment

0 Comments