Google example | Selenium Forum
M
Posted on 30/08/2015
gettext() code is not working for me...can u let me know what the issue is?

public class Google {

public static void main(String[] args) {

WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

driver.get("https://www.google.com/");
driver.manage().window().maximize();



driver.findElement(By.xpath("//input[@name='q']")).sendKeys("hello");
driver.findElement(By.xpath("//button[@class= 'lsb']")).click();
driver.findElement(By.xpath("//input[@name='q']")).sendKeys(Keys.ENTER);
driver.findElement(By.xpath("//ol[@id='rso']/div[2]/div[1]/div/h3/a]")).getText();

M
Replied on 30/08/2015

"//ol[@id='rso']/div[2]/div[1]/div/h3/a]"

this xpath will keep on changing and maybe thats why its not working.

what is the text you want to get from Google.


M
Replied on 31/08/2015

It's the google example which u gave on friday.

Steps:

1.Go to google.com web page.
2.type "Hello".
3.Search.
4.get text of the first link on the page.


M
Replied on 31/08/2015

WebDriver driver = FirefoxDriver();
driver.get("www.google.com");
List<WebElement> elements = driver.findElements(By.tagName("a"));