【发布时间】:2019-07-17 21:45:38
【问题描述】:
我正在尝试编写一个能够执行以下操作的测试: 1. 导航到一个网站。 2. 导航到菜单下的页面。 3. 进入该页面后,断言我想要的图像显示在标有“SECTION”的部分下。
这是我的代码(方法 1):
public void test1() throws Exception {
WebElement compare_image = driver.findElement(By.linkText("URL link where the image is located"));
driver.get("website URL");
WebElement image = driver.findElement(By.cssSelector("cssSelector for image from FireFox -> inspect element -> copy CSS selector"));
assertEquals(image, compare_image); }
我对 Selenium 和 QA 自动化非常陌生,因此我将不胜感激任何详细的帮助,因为到目前为止我的谷歌搜索还不够。它给了我一个元素不存在的 findElement 调用异常,但我不知道为什么当我尝试了所有可以从检查元素获得的 Bys 时。
我的处理方法正确吗?如果没有,我能做些什么不同的事情?
【问题讨论】:
-
所以你想验证一个元素指向图像还是你想验证图像本身?例如IMG src 与两张图片的逐位比较是否正确?
标签: selenium selenium-webdriver selenium-chromedriver selenium-ide build-automation