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按ID查找元素-Selenium是否在注释上循环?_Java_Selenium_Testing_Gwt_Automated Tests - Fatal编程技术网

Java/Selenium按ID查找元素-Selenium是否在注释上循环?

Java/Selenium按ID查找元素-Selenium是否在注释上循环?,java,selenium,testing,gwt,automated-tests,Java,Selenium,Testing,Gwt,Automated Tests,目前,我正在开发一个相对较小的GWT应用程序,并使用Selenium测试GUI。一切正常,但当我写测试时,一个问题突然出现在我的脑海中: 在我的Dummy页面上,我执行以下操作: public class DummyPage { @FindBy(id = ID_SEARCH_BTN) private WebElement btnSearch; @FindBy(id = ID_CANCEL_BTN_CLEAR) private WebEleme

目前,我正在开发一个相对较小的GWT应用程序,并使用Selenium测试GUI。一切正常,但当我写测试时,一个问题突然出现在我的脑海中:

在我的Dummy页面上,我执行以下操作:

public class DummyPage 
{

    @FindBy(id = ID_SEARCH_BTN)     
    private WebElement btnSearch;

    @FindBy(id = ID_CANCEL_BTN_CLEAR)   
    private WebElement btnClear;
    ...

    public DummyPage() 
    {
        eventFiringDriver = DriverFactory.getInstance().getEventFiringDriver();
        PageFactory.initElements(eventFiringDriver, this);
    }

    WebDriverWait webDriverWait = new WebDriverWait(eventFiringDriver, 20);
    wait = webDriverWait.ignoring(StaleElementReferenceException.class);
}
在我的应用程序中,如果用户单击按钮,则会显示一个自定义对话框,该对话框是在按钮的clickHandler中构建的,因此它在页面上不存在?我给自定义对话框上的按钮传递了一个ID,以便在测试页面上找到它

我的问题是,如果我试图通过以下方式找到对话框上的按钮:

@FindBy(id = DIALOGBOX_YES_BTN)
private WebElement dialogBoxYesBtn;
对象是空的吗?还是在创建WebElement时提取它?Selenium是否在
@FindBy
注释上循环并尝试解析它们

现在我有一个测试,我点击第一个按钮,然后用同样的方法,我试着找到带有ID的DialogBoxButton——它正在工作,但如果我能将所有WebElements设置在页面对象的顶部,那就太好了

提前感谢您的帮助。

Selenium是否在注释上循环?答案是肯定的,如果您正在对预期的WebElement执行某些操作,Selenium将在该WebElement上循环。所以在你的情况下,如果你提到

@FindBy(id = DIALOGBOX_YES_BTN)
private WebElement dialogBoxYesBtn;
因此,当您尝试在脚本中的任何位置使用此webelement时

dialogBoxYesBtn.click();
驱动程序将首先在当前页面上找到它,然后在WebElement上模拟操作。如果找不到,它将抛出异常


有关详细信息,请参阅。

是的,您可以将其添加到页面对象中。除非使用了缓存注释,否则每次对对象执行操作时都会提取该对象。在IMO中,从
PageObject
中初始化
PageObject
可能不是一个好主意。根据您的问题,如果
用户单击按钮,将显示一个自定义对话框
,这基本上意味着
自定义对话框
HTML DOM的一部分
,我们应该能够从相同的
页面对象
处理它。