Selenium CSS selector :visible is not a valid selector

css, selenium, xpath

Solution

@FindBy(css = "a[data-code=panel]")
private List<WebElement> cpaneladmin;

Then iterate through the elements until you find the one that is displayed.

public WebElement FindDisplayed(WebElements elements)
{
    foreach (WebElement element in elements)
    {
        if (element.isDisplayed()) // correct method: isDisplayed()
            return element;
    }
}

Problem

I'm using Page Objects to map elements in a page, something like that: ``` public class MyPage { protected WebDriver driver; @FindBy(css = "a[data-code=panel]:visible") private WebElement cpaneladmin; public MyPage(WebDriver driver) { this.driver = driver; PageFactory.initElements(this.driver, this); } } ``` The problem is this `:visible` CSS selector. Aparently, Selenium does not support it. Is there a way to select only visible elements using xpath or another kind of CSS selector? Thanks

Original source