Selenium @当元素状态不可见时,FindBy批注找不到元素

Selenium @当元素状态不可见时,FindBy批注找不到元素,selenium,serenity-bdd,cucumber-serenity,findby,Selenium,Serenity Bdd,Cucumber Serenity,Findby,当元素状态不可见时,@FindBy注释找不到元素。我们正在编写一些SEO测试,这些元素在网页上是不可见的 例如,以下操作不起作用 @CacheLookup @FindBy(xpath = "//meta[@name='description']") public WebElementFacade metaDescription; 但这是可行的 WebElement metaV2 = getDriver().findElement(By.xpath("//meta[@name='descript

当元素状态不可见时,
@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
有什么想法吗


谢谢

WebElementFacade希望在与元素交互之前元素是可见的(许多标准WebElement方法也是如此)。如果要检查不可见元素,请使用WebElement或完全避免使用@FindBy,例如

By META_V2 = By.xpath("//meta[@name='description']")
.
.
.
$(META_V2).shouldBePresent();

WebElementFacade希望元素在与之交互之前可见(许多标准WebElement方法也是如此)。如果要检查不可见元素,请使用WebElement或完全避免使用@FindBy,例如

By META_V2 = By.xpath("//meta[@name='description']")
.
.
.
$(META_V2).shouldBePresent();

使用findBy annotation时,您会看到什么错误?@CacheLookup正在缓存初始查找的结果,并确保不会再次尝试查找元素。这可能会导致一些意外的副作用。如果要等到某些内容可见,最好的选择是使用显式等待。如果没有@CacheLookup,它也无法工作。在使用findBy批注时,您会看到什么错误?@CacheLookup正在缓存初始查找的结果,并确保它不会再次尝试查找元素。这可能会导致一些意外的副作用。如果您想等到某些内容可见,最好的选择是使用显式等待。如果没有@CacheLookup,它也无法工作。