如何使用java和selenium web驱动程序循环webelements列表?

时间:2014-10-16 06:00:20

标签: java selenium

Hii可以告诉我如何使用java和selenium web驱动程序循环web元素列表 这是我的代码

这些是对象

 By ProjectSummaryReport_Campaign = By.name("q.a.62.d");
 By ProjectSummaryReport_ProjectTitle = By.name("q.a.1.d");
 By ProjectSummaryReport_ProjectAllocation = By.name("q.a.63.d");
 By ProjectSummaryReport_JobNumber = By.name("q.a.2.d");
 By ProjectSummaryReport_ArchivalStatus = By.name("q.a.6.d");
 By ProjectSummaryReport_StartDate = By.name("q.a.7.d");
 By ProjectSummaryReport_EndDate = By.name("q.a.8.d");

这是代码

Wrappers.Click(ProjectSummaryReport_Campaign);
Wrappers.Click(ProjectSummaryReport_ProjectTitle);
Wrappers.Click(ProjectSummaryReport_ProjectAllocation);
Wrappers.Click(ProjectSummaryReport_JobNumber);
Wrappers.Click(ProjectSummaryReport_ArchivalStatus);
Wrappers.Click(ProjectSummaryReport_StartDate);
Wrappers.Click(ProjectSummaryReport_EndDate);

Click_Link方法

public static void Click(By byobj) {
    _driver.findElement(byobj).click();
}

如果有任何问题,请不要开采我对这个硒自动化很新,感谢先进的解决方案

1 个答案:

答案 0 :(得分:0)

你的意思是这样的吗?

    List<WebElement> list = Arrays.asList(WebElement, WebElement1, WebElement2...);
    for(WebElement el : list){
        el.click();
    }