我想做的事情:
我目前正在将我的 Selenium(Java) 框架从标准页面对象模型 + cucumber 设置迁移到 PageFactory + cucumber 设置。
这是我迄今为止所做的尝试并使其发挥作用:
- 我启动了我的 PageFactory。
- 我导入了所有必需的包和依赖项。
- 我检查了多个在线教程以确保我拥有正确的 语法。
我遇到的问题:
我的 IDEA (IntelliJ) 不断在 @FindBy 注释上给出错误,并因此无法编译。
当我将鼠标悬停在 @FindBy 注释上时,它告诉我“@FindBy 不适用于方法”
当我尝试运行测试时,每次出现 @FindBy 注释时都会出现以下错误。 “注释类型不适用于此类声明”
我的问题涉及的代码:
package pageObjects;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
public class AssociatedAlerts {
public AssociatedAlerts(WebDriver driver) {
PageFactory.initElements(driver, this);
}
@FindBy(css = "#Rabo_SelectedBatchSLTransactionrow0 > * > [type = 'checkbox']")
public WebElement firstAlertCheckboxSelected();
}
我一定错过了一些简单的东西,但我似乎无法发现它。 任何帮助将不胜感激。
提前致谢。
最佳答案
您的语法有错误:
@FindBy(css = "#Rabo_SelectedBatchSLTransactionrow0 > * > [type = 'checkbox']")
public WebElement firstAlertCheckboxSelected();
firstAlerchCheckboxSelected 不是一种方法。这是一个变量。
将其更改为:
@FindBy(css = "#Rabo_SelectedBatchSLTransactionrow0 > * > [type = 'checkbox']")
public WebElement firstAlertCheckboxSelected;
关于java - 如何在 Selenium 中正确实现 PageFactory 注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48686845/