假设您正在使用 , 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