Issue
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
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;
}
}
Answered By - Richard
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.