Finding Compound class elements in Selenium Webdriver
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"));
Leave a Comment