Berkay Kirmizioglu
Berkay Kirmizioglu

Reputation: 1185

@FindBy annotations cannot find the element, when element state is not visible

@FindBy annotation cannot find the element, when element state is not visible. We are writing some SEO tests those elements are not visible on webpage.

For example following is not working;

@CacheLookup
@FindBy(xpath = "//meta[@name='description']")
public WebElementFacade metaDescription;

But that works;

WebElement metaV2 = getDriver().findElement(By.xpath("//meta[@name='description']"));

It gives an error like;

org.openqa.selenium.ElementNotVisibleException: Timed out after 15 seconds. Element not available

Any idea ?

Thank you

Upvotes: 0

Views: 1678

Answers (1)

John Smart
John Smart

Reputation: 942

WebElementFacade expects an element to be visible before interacting with it (as do many of the standard WebElement methods). If you want to check an invisible element, use a WebElement or avoid @FindBy entirely, e.g.

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

Upvotes: 2

Related Questions