Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Selenium中正确实现PageFactory注释?_Java_Selenium_Intellij Idea_Cucumber_Page Factory - Fatal编程技术网

Java 如何在Selenium中正确实现PageFactory注释?

Java 如何在Selenium中正确实现PageFactory注释?,java,selenium,intellij-idea,cucumber,page-factory,Java,Selenium,Intellij Idea,Cucumber,Page Factory,我想做什么: 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 Ass

我想做什么:

    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();
}
我目前正在将Selenium(Java)框架从标准页面对象模型+cucumber设置迁移到PageFactory+cucumber设置

这就是我迄今为止所做的努力,以使其发挥作用:

    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();
}
  • 我创办了我的寻呼工厂
  • 我导入了所有必需的包和依赖项
  • 我检查了多个在线教程,以确保我有正确的答案 语法
我遇到的问题:

    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();
}
My 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;

很好的捕获(+1),应该能完成任务。非常感谢!现在它就像一个符咒。谢谢你告诉我背后的原因。吸取的教训。@Ceesiebird很高兴我能提供帮助:)您提供了非常有用的代码示例。快乐编码@RafałLaskowski,让我们假设有时候我希望给出一些关于我的WebElement的参数,我通常会在方法末尾的()中定义这些参数。鉴于上面的代码示例,我该如何设置它?@Ceesiebird提供了一个示例,因为它太抽象了:)