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 上发布了这个程序,所以如果可以的话请看一下这个链接 -为什么我的测试抛出异常 - 无法在网络驱动程序中定位元素? https://stackoverflow.com/questions/20998375/why-my-test-is-throwing-exception-unable-to-locate-element-in-webdriver
请尝试下面。应该有效
List<WebElement> elements = driver.findElement(By.LinkText("Gmail"))
elements.get(0).click().
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)