java - webdriver 无法单击 Firefox 中的超链接

标签 java eclipse firefox selenium selenium-webdriver

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);
    }

}

今天我试图测试 Google 主页(www.google.co.in)上提供的 Gmail 链接。我能够启动 fierfox 窗口,并且它能够执行第一步,将我带到 google 主页,但之后什么也没有发生,我也没有收到任何运行时错误或 eclipse 的任何异常。不知道网络驱动程序发生了什么。 我遇到了另一个程序的问题,我已经在 stakwave 上发布了这个程序,所以如果可以的话请看一下这个链接 - Why my test is throwing Exception-Unable to locate element in webdriver?

最佳答案

请尝试以下。应该可以工作

List<WebElement> elements = driver.findElement(By.LinkText("Gmail"))
elements.get(0).click().

关于java - webdriver 无法单击 Firefox 中的超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21018649/

相关文章:

java - Java 中 SQL 连接的问题

eclipse - Eclipse 中的排序方法

java - 从整数数组中得到奇怪的结果

java - BlackBerry 模拟器和 BIS 推送服务

java - 如何从 PNG 中删除 Gamma 信息

java - 如何让Java访问Cassandra 1.0.10

eclipse - 如何让 Eclipse JSP 表达式语言验证接受 JSP 2.2 EL 构造?

firefox - CSS 过渡,通过负的顶部/左侧绝对位置

Firefox 中的 CSS 显示类型表行元素高度

css - 溢出-x : visible; overflow-y: auto; does not work - is this standards compliant?