SteelBird82
SteelBird82

Reputation: 769

How to verify whether a div tag is present or not using Selenium WebDriver in C#?

How to verify whether a div tag is present or not using Selenium WebDriver in C#?

On my web page, I would like to verify whether for the below div tag, to ensure that the data is displayed. What is the right way of doing this?

div data-bind="visible: displayFeatureExposures" style=""

Upvotes: 0

Views: 465

Answers (2)

har07
har07

Reputation: 89315

Alternatively, if you don't want to rely on exception to determine whether the element exists or not, you can use FindElements() and check for the number of elements returned :

string query = "//div[@data-bind='visible: displayFeatureExposures']";
bool isExists = driver.FindElements(By.XPath(query)).Count > 0;

Upvotes: 0

nemelianov
nemelianov

Reputation: 909

You can check it like this:

new WebDriverWait(webDriver, TimeSpan.FromSeconds(timeOut)).Until(ExpectedConditions.ElementExists((By.XPath("//div[contains(@data-bind, 'displayFeatureExposures')]"))));

Upvotes: 1

Related Questions