从 Selenium 中的另一个框架访问一个框架的数据

Access data of a frame from another frame in Selenium

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

我的问题是: 我在页面 A 上有一个 table 显示一些搜索结果。 如果我 select 任何一行,然后单击提交按钮,将加载下一页。 页面 B(下一页)包含一个下拉列表,我必须验证它包含的值与我从页面 A 上的 table select 编辑的值完全相同。

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

假设您正在使用 Selenium Java Client 我们可以借助 Java Collection 来比较 2 ArrayList。这里有一个示例原型供您参考:

//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