Reputation: 1462
package testproject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class WeblinkTest {
public static void main(String[] args) throws InterruptedException {
// Creating a fierfox driver/window
WebDriver driver= new FirefoxDriver();
//Assigning address of the webpage which you want to check
driver.get("https://www.google.co.in/");
Thread.sleep(2000);
//Creating and Identifing--By.xpath the element on which you want testing
WebElement wb1= driver.findElement(By.xpath(".//*[@id='gb']/div[1]/div[1]/div[1]/div[2]"));
wb1.click();
Thread.sleep(2000);
}
}
Today i was trying to test a gmail link which is available on Google homepage(www.google.co.in). I am able to launch a fierfox window and also it is able to do the first step which is taking me to google homepage but after that nothing is happening neither i am getting any run time error or any exception from eclipse. Don't know what is going on with the webdriver. I was facing problem with one more program which i already posted on stakwave so if u can then please have a look at this link-Why my test is throwing Exception-Unable to locate element in webdriver?
Upvotes: 0
Views: 1464
Reputation: 1462
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.
Upvotes: 0
Reputation: 7008
This should work,
new WebDriverWait(driver,30).until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Gmail"))).click();
Upvotes: 0
Reputation: 4923
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();
Upvotes: 0
Reputation: 8251
Please try below. It should work
List<WebElement> elements = driver.findElement(By.LinkText("Gmail"))
elements.get(0).click().
Upvotes: 1
Reputation: 4923
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.
Upvotes: 0
Reputation: 648
Try with implimentig implicit wait after driver initializes. by adding below line driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
Upvotes: 0