i want to particularly solve this problem using javascript executor which am not very familiar with. I have a auto suggestive dropdown(not select) where am sending sendkeys("ind") and using keysdown am iterating through the options.
the autosuggestive dropdown HTML:
<input type="text" id="autocomplete" class="inputs ui-autocomplete-input" placeholder="Type to Select Countries" autocomplete="off">
the dropdown HTML:
`British Indian Ocean Territory
India
Indonesia
`> public class a103Section12ScrollingTable {
public static void main(String[] args) throws InterruptedException {
TODO Auto-generated method stubSystem.setProperty(“webdriver.chrome.driver”, C:/chromedriver/chromedriver-win64/chromedriver.exe”);
WebDriver driver = new ChromeDriver();
driver.get(“https://rahulshettyacademy.com/AutomationPractice/”);
JavascriptExecutor js = (JavascriptExecutor) driver;int count = 0;
WebElement autocomplete = driver.findElement(By.id(“autocomplete”));
driver.findElement(By.id(“autocomplete”)).sendKeys(“ind”);
Thread.sleep(1000);
driver.findElement(By.id(“autocomplete”)).sendKeys(Keys.DOWN);
String actualValue = (String) js.executeScript(“return document.getElementById(‘ui-id-1’).value;”);
scrolling throgh the field
while (!actualValue.equals(“India”)) {
driver.findElement(By.id(“ui-id-1”)).sendKeys(Keys.DOWN);
driver.findElement(By.id(“ui-id-1”)).sendKeys(Keys.ENTER);
count++;
Thread.sleep(1000);
System.out.println(count);
if (!actualValue.equalsIgnoreCase(“india”)) {
String d = “return document.getElementById(‘ui-id-1’).value;”;
String n = (String) js.executeScript(d);
System.out.println(n);
System.out.println(count);