1

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

  • First off, welcome to SQA, @Fahmed! Have you tried this approach: source.sendKeys("kar"); source.sendKeys(Keys.Enter) or, source.sendKeys(Keys.Tab)? – Brian Apr 12 at 17:45
  • when i try manually, pressing the DOWN key does not work to select a item – globalworming Apr 16 at 8:54
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.