我正在尝试点击 alibaba.com 网站上的登录链接
这是我的测试用例:
public class TestCase {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
String URL = "http://www.alibaba.com/";
WebDriver driver;
System.setProperty("webdriver.chrome.driver",
"D:\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.get(URL);
Thread.sleep(2000);
SignIn.SignIn_click(driver).click();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我定位 web 元素的对象类
package PageObjects;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class SignIn {
private static WebElement element = null;
public static WebElement SignIn_click(WebDriver driver) {
element = (new WebDriverWait(driver, 10)).until(ExpectedConditions
.visibilityOfElementLocated(By
.xpath("//a[@data-val='ma_signin']")));
element = driver.findElement(By
.xpath("//a[@data-val='ma_signin']")); …Run Code Online (Sandbox Code Playgroud)