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.
Autosuggestive dropdown HTML:
<input type="text" id="autocomplete" class="inputs ui-autocomplete-input" placeholder="Type to Select Countries" autocomplete="off">
The dropdown options HTML:
<ul id="ui-id-1" tabindex="0" class="ui-menu ui-widget ui-widget-content ui-autocomplete ui-front" style="display: none; top: 325.792px; left: 264.52px; width: 231px;"> <li class="ui-menu-item"><div id="ui-id-81" tabindex="-1" class="ui-menu-item-wrapper">British Indian Ocean Territory</div></li><li class="ui-menu-item"><div id="ui-id-82" tabindex="-1" class="ui-menu-item-wrapper">India</div></li>
<li class="ui-menu-item"><div id="ui-id-83" tabindex="-1" class="ui-menu-item-wrapper">Indonesia</div></li></ul>
TODO Auto-generated method stub
driver.get("https://rahulshettyacademy.com/AutomationPractice/");
JavascriptExecutor js = (JavascriptExecutor) driver;
int count = 0;
WebElement autocomplete = driver.findElement(By.id("autocomplete"));
trying to send the text via senkeys & keysdown
driver.findElement(By.id("autocomplete")).sendKeys("ind");
driver.findElement(By.id("autocomplete")).sendKeys(Keys.DOWN);
this is the lie with issue. am trying to fetch the values of the HTML
tag with dropwdown options. how should this line be corrected?
String actualValue = (String) js.executeScript("return Document.querySelectorAll('#ui-id-1 li');");
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.querySelectorAll('#ui-id-1 li');";
String n = (String) js.executeScript(d);
System.out.println(n);
System.out.println(count);