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/