【发布时间】:2021-10-02 14:39:02
【问题描述】:
我对 Selenium 很陌生。
我尝试构建一个测试来验证网页上是否显示了网页元素(小图标)。
因此,在我的班级顶部,我通过 xpath 定义了 Web 元素。
右键单击元素并单击检查后,我从检查中复制了 Xpath。
@FindBy(xpath = "//*[@id="referrals"]/tbody/tr[2]/td[2]/div/img[2]") 私有WebElement ChainAndTwoArrowsIcon;
然后在同一个类中,我有一个方法来评估我的图标是否出现:
public boolean IconChainWithArrowIsFound() throws InterruptedException {
return ChainAndTwoArrowsIcon.isDisplayed()
&& ChainAndTwoArrowsIcon.getAttribute("title").toString().contains("Associated, and was successfully sent.");
}
这是我代码的最后一点,我在同一代码中使用的所有 xpath 引用在所有代码中都运行良好。
但是,对于我描述的这一点,我在运行结束时遇到错误:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="referrals"]/tbody/tr[ 2]/td[2]/div/img[2]"}
请看附图
我可以就可能出现的问题提出建议吗? 提前谢谢你。
【问题讨论】: