从Selenium中的另一帧访问帧的数据

时间:2017-10-25 12:08:49

标签: selenium iframe automation pega

我正在使用Selenium为我的组织自动化基于PEGA的Web应用程序。 PEGA应用程序有很多iframe。

我的问题是: 我在页面A上有一个表格,显示一些搜索结果。 如果我选择任何一行,然后单击“提交”按钮,则会加载下一页。 页面B(下一页)包含一个下拉列表,我必须验证它是否包含我从页面A上的表格中选择的完全相同的值。

通过切换到帧然后转换为默认内容,我所有其他自动化场景都可以正常工作。但是,这种情况不允许我将页面A(使用ArrayList)上的搜索结果传递给页面B(包含另一个ArrayList)。我必须比较这两个Arraylists,唯一的问题是跨帧传递/访问数据。

1 个答案:

答案 0 :(得分:0)

假设您使用的是 Selenium Java Client ,我们可以借助 Java Collection 来比较2 ArrayList < / strong>即可。以下是供您参考的示例原型:

//Switch to the first frame
driver.switchTo().frame("firstFrame"); 
//Collect the WebElements, retrive the text and save in a List
List<WebElement> team_member = driver.findElements(By.xpath("xpathA"));
List<String> mem_name_list = new ArrayList<String>();
for (WebElement member:team_member)
{
    String memeber_name = member.getAttribute("innerHTML");
    mem_name_list.add(memeber_name);
}
//Switch back to Top Window
driver.switchTo().defaultContent();
//Switch to the second frame
driver.switchTo().frame("secondFrame");
//Collect the WebElements, retrive the text and save in a List
List<WebElement> team_member_images = driver.findElements(By.xpath("//main[@id='content']//div[@class='team-members']/div[@class='team-member']/div[@class='team-member-portrait']/img"));
List<String> mem_image_list = new ArrayList<String>();
for (WebElement image_link:team_member_images)
{
    String memebr_image = image_link.getAttribute("src");
    mem_image_list.add(memebr_image);
}
//Switch back to Top Window
driver.switchTo().defaultContent();
//Assert the two List<String> in a loop