Not able to select autosuggest value in input box | Selenium Forum
M
Posted on 02/10/2015
Hi Ashish/Team,

I was working on Question 4 (cathaypacific)given in module 17 exercise. But got stuck at one place because not able to select any value in destination input box which comes through autosuggestion. Though i am able to see value coming in but seems to not visible (As IsDisplayed() is false). Could you please help me with this?
Note : I also tried Actions.moveToElement(Element).clickAndHold().build.perform();

package qtpselenium.tutorial17;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class CopyOfExcercise_4 {
public static WebDriver driver;
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"\\resources\\"+"chromedriver.exe");
driver= new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://www.cathaypacific.com/cx/en_IN.html");
driver.findElement(By.cssSelector("#depart-label")).clear();
driver.findElement(By.cssSelector("#depart-label")).sendKeys("Boston");
Thread.sleep(2000);
driver.findElement(By.xpath("//a[starts-with(@id,'ui-id') and contains(text(),Boston)]")).click();
Thread.sleep(2000);
driver.findElement(By.cssSelector("#destination-label")).clear();
Thread.sleep(1000);
driver.findElement(By.cssSelector("#destination-label")).sendKeys("London");
WebElement destination=driver.findElement(By.xpath("//*[starts-with(@id,'ui-id') and contains(text(),London)]"));
//Actions act = new Actions(driver);
//WebElement destination=driver.findElement(By.xpath("//a[starts-with(@id,'ui-id')]"));
//System.out.println(destination.isEnabled());
//System.out.println(destination.isDisplayed());
//act.moveToElement(destination).clickAndHold().build().perform();
Thread.sleep(5000);
//act.release(destination);
destination.click();

driver.findElement(By.xpath("//*[@id='book-trip-tab-panel']/div/div/form/button]")).click();


}

}

M
Replied on 02/10/2015

use this. i used keys.return

package com.soapuitutorial.propertie;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class CopyOfExcercise_4 {
public static WebDriver driver;

public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver",
"D:\\Vaibhav\\selenium2\\DatadrivenTestng\\src\\resource\\chromedriver.exe");

driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://www.cathaypacific.com/cx/en_IN.html");
Thread.sleep(5000);
driver.findElement(By.cssSelector("#depart-label")).clear();
driver.findElement(By.cssSelector("#depart-label")).sendKeys("Boston");
Thread.sleep(2000);
driver.findElement(
By.xpath("//a[starts-with(@id,'ui-id') and contains(text(),Boston)]"))
.click();
Thread.sleep(2000);
driver.findElement(By.cssSelector("#destination-label")).clear();
Thread.sleep(1000);
driver.findElement(By.cssSelector("#destination-label")).sendKeys(
"London");
driver.findElement(By.cssSelector("#destination-label")).sendKeys(
Keys.RETURN);

// Actions act = new Actions(driver);
// WebElement
// destination=driver.findElement(By.xpath("//a[starts-with(@id,'ui-id')]"));
// System.out.println(destination.isEnabled());
// System.out.println(destination.isDisplayed());
// act.moveToElement(destination).clickAndHold().build().perform();
Thread.sleep(5000);
// act.release(destination);


driver.findElement(
By.xpath("//*[@id='book-trip-tab-panel']/div/div/form/button]"))
.click();

}

}


M
Replied on 06/10/2015

Cool.. Thanks.