Skip to content

Finding Compound class elements in Selenium Webdriver

by on May 15, 2014

Now we are seeing web applications and sites utilising Bootstrap or emulating these layouts, it’s becoming more of a pain to identify a specific element by class when using FindElement(By.ClassName()).

I recently found out that WebDriver doesn’t support Compound Classes when searching By.ClassName.

In order to get around this, you’ll need to search by CssSelector instead.

Here’s an example:
You can include compound class names selectors by leaving no gap between any of them.
For example if your div is:

<div class="k-calendar-container k-popup k-group k-reset"></div>

then your selector will be:

driver.FindElement(By.CssSelector("k-calendar-container.k-popup.k-group.k-reset"));

From → C#, Selenium

Leave a Comment

Leave a comment

NE1 Atoll

The Official blog of NE1 Games

Selenium for .Net using C# language

Adventures in Coding, gaming and other fun things in my life

Coded UI 101 - Understanding Coded UI Tests

Adventures in Coding, gaming and other fun things in my life