package testproject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.
Please try below. It should work
List<WebElement> elements = driver.findElement(By.LinkText("Gmail"))
elements.get(0).click().
The XPATH in the code is DIV element but you want to click on ANCHOR Gmail So update the xpath for ANCHOR and click on it.
I have posted this question in Jan saying that the web-driver was not able to click on the hyperlink and just now i got the solution. Actually the xpath for the hyperlink was not accurate. I had used this xpath- .//*[@id='gb']/div[1]/div[1]/div[1]/div[2] which was locating the logo but not the button.
Today i changed it by .//*[@id='gb']/div[1]/div[1]/div[1]/div[2]/a and now its working absolutely fine.
Please don't be angry on me because i was going through the questions which i had asked from the forum and found this question. I got the solution for the problem thats why i am sharing this.
Try with implimentig implicit wait after driver initializes. by adding below line driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
I have tested the below code,it clicks on GMAIL link on google page,if your question is solved then select as answer
WebDriver driver= new FirefoxDriver();
driver.get("https://www.google.co.in/");
WebElement wb1= driver.findElement(By.xpath(".//*[@id='gb']/div[1]/div[1]/div[1]/div[2]/a"));
wb1.click();
This should work,
new WebDriverWait(driver,30).until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Gmail"))).click();