Not able to get Text of google search auto-suggession | Selenium Forum
M
Posted on 28/07/2016
Hi,

I am trying to get the text of one of the auto-suggession from google search. but not getting the same and getting below error. i tried starts-with function as well with Xpath.

My code is:
package ObjectIdentification;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class ElementsWithLilData {
@Test
public void yahooTest()
{
System.setProperty("webdriver.chrome.driver","D:\\Selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
/*driver.get("http://yahoo.com");
driver.findElement(By.xpath("//*[@id='UHSearchBox']")).sendKeys("games");
String st = driver.findElement(By.xpath(".//*[starts-with(@id,'yui_3_12_0_1')]/li[1]/a")).getText();
System.out.println("This is the text");
System.out.println(st);
driver.close();*/

driver.get("http://yahoo.com");
System.out.println("Yahoo is opened");
driver.findElement(By.xpath("//*[@id='UHSearchBox']")).sendKeys("games");
System.out.println("games is enetered");
//*[@id='yui_3_12_0_1_1469737370539_422']/li[1]/a
String str = driver.findElement(By.xpath("//*[starts-with(@id, 'yui_3_12_0_1')]/li[1]/a")).getText();
System.out.println(str);

}

}

Output i am expecting is: "Games for girls"
Actual output i am getting is :
Yahoo is opened
games is enetered
?
Virat's epic weightlifting session
PASSED: yahooTest

M
Replied on 28/07/2016

Got the updates... Had to wait for some secs before selecting the option
added Thread.sleep(3000);


M
Replied on 28/07/2016

will you be using grid?