1
votes

here is the code:

<div class="padding-tlb"> 
....Some code....
</div>
    <article class="non-article-login">
          <div class="one-fourth-percent columns-percent">&nbsp;</div>
          <div class="one-half-percent columns-percent">
            <div class="one-fourth-percent columns-percent">
              User ID
            </div>
     </div>
     </div>
        </article>

I want to check if exist the class "one-fourth-percent columns-percent".

   WebElement test = driver.findElement(By.className("one-fourth-percent columns-percent"));

But doesn't works, here is the error:

org.openqa.selenium.InvalidSelectorException: The given selector one-fourth-percent columns-percent is either invalid or does not result in a WebElement. The following error occurred: InvalidSelectorError: Compound class names not permitted

But if I try to find the article class - it's fine. It's look like, everything outside of article class works. This is FINE:

  WebElement test = driver.findElement(By.className("padding-tlb"));

How to get inside this article class, and check the values?

3
is the article get loaded by ajax maybe? - peetya
use this xpath: By.xpath("//article[@class='non-article-login']/div[1]"); - Saritha G

3 Answers

1
votes

Compound classes are not allowed in webdriver. That it was the InvalidSelectorError is telling you. Your best option is to select by cssSelector instead. Something like:

WebElement test = driver.findElement(By.cssSelector("one-fourth-percent.columns-percent"));
0
votes

This issue Compound class names not permitted occurs because the class name has multiple words you can resolve this by using the below xpath

driver.findElement(By.xpath("//article/div[contains(@class,'one-fourth-percent')]")

Hope this helps you.Kindly get back if you have any queries

0
votes

Thanks everyone, only this works and helps:

driver.findElement(By.xpath("//article/div[contains(@class,'one-fourth-percent')]"));