unable to select desired element from the list populated with AutoSuggest Dropdown



  • On https://www.emirates.com/us/english/ site Departure Airport DropDown I am trying to select 3rd option Jakarta here by typing the keyword KAR but I am unable to do that. It types the keyword kar and then displays the suggested options but does not select 3rd option Jakarta. Please help. Attaching the picture of the dropdown and code i am running:

    driver.get("https://www.emirates.com/us/english/"); 
    Thread.sleep(3000);
    System.out.println(driver.getCurrentUrl()); 
    driver.manage().window().maximize();
    ((JavascriptExecutor)driver).executeScript("scroll(0,250)");
    WebElement source=driver.findElement(By.xpath("//input[@name='Departure Airport']"));
    source.clear();
    source.sendKeys("kar");
    
    for(int i=1;i<=3;i++)
    {
        source.sendKeys(Keys.DOWN);
        Thread.sleep(1000);
    }
    
    source.sendKeys(Keys.ENTER);
    System.out.println(source.getAttribute("value"));
    

    enter image description here



  • The keys.DOWN is send to the element source not the browser.

    According to the code of sendkeys:

    • Use this method to simulate typing into an element, which may set its value.

    It might not even truly send the actual keys, but change the value of the element.

    I would try the Actions to sendkeys to the browser instead.

    (new Actions(driver)).sendKeys(Keys.DOWN).perform();
    

    Alternatively just search the full location with the word "Jakarta + ENTER" instead of using a partial search on KAR, unless you are testing the dropdown itself. Since the dropdown is probably part of a framework I would let the dropdown testing to the framework builders so you can focus on the application behaviour.


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2