errors when using class names locators Getting compound classes are not supported

0 votes

I have written a method which will count the no of elements in <divs> and will return the number.

 public int getNumberOfOpenBets() {

     openBetsSlip = driver.findElement(By.id("form_open_bets"));
     openBets = openBetsSlip.findElements(By.className(" cashout_noCash"));
     return openBets.size();
 }

This is the page source:

<form id="form_open_bets" method="post" name="form_open_bets">
    <input type="hidden" value="" name="action">
    <input type="hidden" value="" name="bet_id">
    <input type="hidden" value="" name="cashout_price">
    <input id="target_page" type="hidden" value="" name="target_page">
    <div id="By.id" class="slipWrapper ">
        <div id="openBets_header"></div>
        <div id="cashout_1626" class=" cashout_noCash">
            <div id="cashout_1625" class=" cashout_noCash">
                <div id="cashout_1615" class=" cashout_noCash">
                    <div id="cashout_1614" class=" cashout_noCash">
                        <div id="cashout_1613" class=" cashout_noCash">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>

Below is the error log. Seems like WerbDriver doesn't support spaces in class names. Can anyone please guide me to use CSS selector in order to find the elements?

Compound class names are not supported. Consider searching for one class name and filtering the results or use CSS selectors.

org.openqa.selenium.InvalidSelectorException: Compound class names are not supported. Consider searching for one class name and filtering the results or use CSS selectors.
For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_17'
Driver info: driver.version: unknown
    at org.openqa.selenium.By.className(By.java:131)
    at elements.betslip.Betslip.getNumberOfOpenBets(Betslip.java:136)
    at testSomething(SomethingTest.java:117)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
May 29, 2018 in Selenium by eLiJha
• 770 points
2,731 views

1 answer to this question.

0 votes

Pretty straight forward..If your class name includes a space, WebDriver will see it as a "compound selector". Thats why this throws an error: 

By.className(" cashout_noCash")

You should either eliminate the white space in your By.className() locator. This should still find elements you're looking for or you can find using CSS selectors. Something like this will work according to the exception: 

By.cssSelector(".cashout_noCash") 
answered May 29, 2018 by sniffy_god
• 780 points

Related Questions In Selenium

0 votes
1 answer

Compound class names not permitted

Instead of using Class name you can ...READ MORE

answered Jan 11, 2019 in Selenium by Fujistu
6,306 views
0 votes
1 answer

Getting CSS class name using Selenium Webdriver

You can use getAttribute(attributeLocator) function.  selenium.getAttribute(//xpath@class); You have to specify the ...READ MORE

answered Apr 9, 2018 in Selenium by ghost
• 1,790 points
1,357 views
0 votes
1 answer
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
12,711 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,608 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
6,680 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,551 views
0 votes
2 answers

When executing my Jenkins tests with Selenium WebDriver, I do not see a GUI.

Hi eLiJha, I also faced the same issue ...READ MORE

answered Jul 15, 2019 in Selenium by nayan
• 160 points
12,426 views
+1 vote
2 answers

Is it possible to scroll down in a webpage using selenium webdriver programmed on python?

I using next code for facebook for ...READ MORE

answered May 16, 2019 in Selenium by mslavikas@gmail.com
25,584 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP