首页 > 解决方案 > 除非我手动单击浏览器元素,否则 Chromedriver 不起作用

问题描述

我是 selenium 的新手,正在尝试并行运行 firefox 和 chrome 的基本测试。Everthing 适用于 Firefox,但 chrome 无法正常工作。实际上 chrome 浏览器会打开,但什么都不做,除非我单击电子邮件输入,然后单击任何期望电子邮件输入的位置。当我这样做时,我的测试从 chrome 开始,一切正常。我真的很确定我不应该手动单击开始测试:)

这是我的页面对象;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import page.objects.AbstractPageObject;

public class LoginPage extends AbstractPageObject {

@FindBy(xpath = "//input[@type='email']")
private WebElement email;

@FindBy(xpath = "//input[@type='password']")
private WebElement password;

@FindBy(xpath = "//button[@type='submit']")
private WebElement continueButton;

public void verifyAllElementsAreDisplaying() {
    email.isDisplayed();
    password.isDisplayed();
    continueButton.isDisplayed();
}

public void fillEmail (String userEmail) {
    email.clear();
    email.sendKeys(userEmail);
}

public void fillPassword (String userPassword) {
    password.clear();
    password.sendKeys(userPassword);
}

public void login () {
    this.continueButton.click();
}
}

这是我的测试;

import org.testng.annotations.Test;
import page.objects.Login.LoginPage;

public class VerifyLogin extends BaseTest {

@Test(description = "Verfifies Login Page Functionality")
public void verifyLogin() throws InterruptedException {
    LoginPage loginPage = new LoginPage();
    loginPage.verifyAllElementsAreDisplaying();
    loginPage.fillEmail("email");
    loginPage.fillPassword("***");
    Thread.sleep(2000);
}
}

在 BaseTest 类中,我有 @BeforeSuit 和 @AfterSuite 注释来管理驱动程序。

标签: seleniumselenium-webdriverselenium-chromedrivertestngchromium

解决方案


推荐阅读