Selenium Webdriver和PageFactory初始化List< WebElement>.元素 [英] Selenium Webdriver and PageFactory initialize List<WebElement> elements

查看:116
本文介绍了Selenium Webdriver和PageFactory初始化List< WebElement>.元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了Google代码上托管的Selenium Webdriver APi文档.当前使用PageFactory初始化我的Page对象,但是在初始化WebElement列表时遇到问题.

I have searched the Selenium Webdriver APi docs hosted on google code. Currently using the PageFactory to initlize my Page objects, but having issue initilizing a list of WebElement.

我需要的是一种初始化元素列表的方法,理想情况下是下拉选择框的列表.

What I need is a way to initialize a list of elements, ideally a list of drop-down select boxes.

我已经看过对@Findsby和@ByChained的API引用,但是仍然无法找出初始化下拉选择框列表的最佳方法.我可以分别为每个元素分配一个WebElement并获取ID,但我想初始化一个列表选择列表

I have looked at the API references to @Findsby and @ByChained but still can not figure out the best way to initlize a list of dropdown select boxes. I COULD have a seperate WebElement for each one and grab the ID but I would like to initlize a list of List selects

public class PageObject {

        @FindBy(id="element_id")
        private WebElement element;

        public getElement() {
          return element;
        }
}

是否有某种方法可以使用与以下内容相似的内容:

public class PageObject {   

    @FindBys(className="selectItmes")
    private List<WebElement> selects;

    public List<WebElement> getSelects() {
      return selects;
    }  
}

还是我必须为每个元素使用单个Web元素? :(

Or must I use a single Web Element for each element? :(

任何人都知道如何使用PageFactory并初始化List元素.使用FindsBy批注.我找不到任何方法,但是硒google文档站点上有google问题,说此问题已在Java api绑定和2.12版中得到修复,因为在2.11中被错误地禁用了....我仍然可以t初始化列表. =/

Anyone know how to use the PageFactory and initlize a List elements; using the FindsBy annotation. I can't find any way of doing this yet there are google issues on the selenium google docs site saying this has been fixed in the Java api bindings and in version 2.12 as it was mistaken disabled in 2.11.... I still can't initialize a list. =/

推荐答案

这是我在测试框架中执行的标准解决方案,直到@FindAllBy在Selenium库中不起作用为止:

Here is standard solution what I do in our test framework, until @FindAllBy doesn't work in Selenium library:

private List<WebElement> selects;

public List<WebElement> getSelects() {
      selects = getDriver().findElements(By.xpath("..."));
      return selects;
    } 

这篇关于Selenium Webdriver和PageFactory初始化List&lt; WebElement&gt;.元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆