【发布时间】:2019-05-24 13:12:26
【问题描述】:
@FindBy 注释找不到元素,当元素状态不可见时。我们正在编写一些 SEO 测试,这些元素在网页上不可见。
例如以下不起作用;
@CacheLookup
@FindBy(xpath = "//meta[@name='description']")
public WebElementFacade metaDescription;
但这行得通;
WebElement metaV2 = getDriver().findElement(By.xpath("//meta[@name='description']"));
它给出了一个类似的错误;
org.openqa.selenium.ElementNotVisibleException: Timed out after 15 seconds. Element not available
有什么想法吗?
谢谢
【问题讨论】:
-
你在使用 findBy 注释时看到了什么错误?
-
@CacheLookup 正在缓存您最初查找的结果,并确保它不会再次尝试查找该元素。这可能会导致一些意想不到的副作用。
-
如果您想等到某些东西可见,最好的选择是使用显式等待。
-
没有@CacheLookup 也无法工作。
标签: selenium serenity-bdd cucumber-serenity findby