Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid Compound Class name error in Page Object?

When I try to use the class name that having space class = "country name" in page object, I'm getting:

Compound class names not permitted Selenium::WebDriver::Error::UnknownError)

How can I use the class name that having space.

Eg:

class = "country name"
like image 483
KAK Avatar asked Jul 23 '13 11:07

KAK


2 Answers

Use a CSS selector instead:

.country.name

The important thing to note is that this example is wrong! If "country name" is meant as a name of a country, that is. Class names can't have spaces in them. In fact, the class attribute is a space-separated list of classes. That means that if you have a class country name, it's not one class, it's two different classes your element belongs to - the first is country, the second is name!

Therefore, fix your classes, if they're wrong. If they're not, use a CSS selector, it's the only reliable way to match multiple classes (apart from a very long and complicated XPath expression). Don't use trivial XPath expressions or CSS selectors with naive attribute comparison (//*[@class='country name'] or *[class='country name']), that's just plain wrong.

like image 98
Petr Janeček Avatar answered Sep 30 '22 01:09

Petr Janeček


You can use with this

By.cssSelector("*[class^='classname']");

^ is for if you entering beginning of the class name, 
$ is for if you entering ending of the class name usage example below with sample class name: tech random corner text_left

By.cssSelector("*[class^='tech']");
By.cssSelector("*[class$='text_left']");
like image 39
gobi Avatar answered Sep 30 '22 00:09

gobi