How to check if an Element exists, when using Page Objects with webdriver.
So far I am doing it this way.
DefaultPage defaultPage = PageFactory.initE
Using C# bindings:
using System.Collections.Generic;
using System.Linq;
public class DefaultPage
{
[FindsBy(How = How.Id, Using = "link_i_user_create")]
private IList userCreateMenuLink;
public bool isUserCreateMenuLinkPresent()
{
return userCreateMenuLink.Any();
}
}
You're telling Selenium to grab all elements that match that Id and put them into a List of IWebElement
. You then call .Any()
on the list which evaluates to true if at least one IWebElement
was found.