SaberTooth
SaberTooth

Reputation: 167

Verifying child elements under a specific class in Selenium Web Driver (Code in C#)

I have an Options field in my website where there are two child options. One is Change Password and other is Logout. I want to verify whether this two options are available there in a sequential order. Which mean the first option should be Change Password and the second option should be Logout. Here is the HTML of that portion:

<div class="user-options-container">
<div class="user-options-header">OPTIONS</div>
<div class="user-options">
<div class="user-options-item" action="changepwd">Change Password</div>
<div class="user-options-item" action="logout">Logout</div>
</div>
</div>

How can I achieve that? What I know is I can get them creating a list of IWebElement class and then verify those elements. But, getting confused on how to do that. I am using Selenium Web Driver 2 and C# as my language.

Upvotes: 0

Views: 1435

Answers (1)

Ant&#39;s
Ant&#39;s

Reputation: 13811

Giving a quick solution on Java. But similar apis should be there in C#.

How about doing like this. For the HTML:

<div class="user-options-item" action="changepwd">Change Password</div>
<div class="user-options-item" action="logout">Logout</div>

get both the WebElement like this:

 List<WebElement> elements =  driver.findByElements(By.class("user-options-item"))

then you can get the text of element like:

elements.get(0).getText() //Change Password
elements.get(1).getText() //Logout

And check their orders. This should work for the given code, but if the same class is shared for other elements too, then the order will change.

Upvotes: 3

Related Questions