Selenium Web-Driver 使用java比较两个不同网站中的数据



请任何人帮助使用可以比较/验证来自两个不同网站的数据的方法。

例如:我想确保第一个 URL 中的"Y"在第二个 URL 中也显示"Y"。

申请| 提交|关闭| N | Y | Y |

---一个 www.sabak.com 中的数据 a:- 验证字母 Y 在第二个 URL 中与 Y 相同

---第二个 www.mandos.com 中的数据 b:- 验证字母"N",如果它在第二个 URL 中与"N"相同

您可以转到第一页,将要比较的值读取到列表中,然后转到下一页并将其中的值与列表中的值进行比较:

//navigate to the first site and get the values you want to compare
    driver.navigate().to("www.sabak.com");
    WebElement element = driver.findElement(By.xpath("xpath to element"));
    List<String> pageOneValues = new ArrayList<>();
    pageOneValues.add(element.getText());
// add more values to the list here as needed
// navigate to the next site and compare the values there with what's in the list
    driver.navigate().to("www.mandos.com");
    WebElement element2 = driver.findElement(By.xpath("xpath to element2"));
    Assert.assertEquals(pageOneValues.get(0), element2.getText());
// do more asserts here for the other values

最新更新