webdriver is not able to click on a hyperlink in firefox

后端 未结 6 2096
不思量自难忘°
不思量自难忘° 2021-01-16 23:01
package testproject;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.         


        
相关标签:
6条回答
  • 2021-01-16 23:36

    Please try below. It should work

    List<WebElement> elements = driver.findElement(By.LinkText("Gmail"))
    elements.get(0).click().
    
    0 讨论(0)
  • 2021-01-16 23:42

    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.

    0 讨论(0)
  • 2021-01-16 23:50

    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.

    0 讨论(0)
  • 2021-01-16 23:51

    Try with implimentig implicit wait after driver initializes. by adding below line driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);

    0 讨论(0)
  • 2021-01-16 23:56

    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();
    
    0 讨论(0)
  • 2021-01-16 23:57

    This should work,

    new WebDriverWait(driver,30).until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Gmail"))).click();
    
    0 讨论(0)
提交回复
热议问题