Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compound class names not permitted error Webdriver

I am getting the following error:

"Compound class names not permitted"

While trying to access web element where-in the element's class name have spaces in between. The page source for the web element is as below.

driver.findElement(By.className("alert alert-success")); 

<div class="alert alert-success" alert-dismissable"="" id="58417" style="display: none;">     <button type="button" class="close hide-panel close-icon-58417" data-dismiss="alert" aria-hidden="true" style="display: inline-block;">×</button><span id="caret-58417" class="notification-caret caret-58417"></span>     <div class="hide-panel close-icon-58417" id="58417" style="display: block;">        <span class="glyphicon glyphicon-ok-sign"></span><strong>Success</strong> KeyLinks Updated Successfully        <div class="notification-panel-body panel-body-58417">REST Invocation Success</div>     </div>  </div>

I tried to find the element by CSS path as below. But the element is not searchable with this.

driver.findElement(By.cssSelector(".alert alert-success")); 

This was the workaround given in the Link but still no success. your help will be much appreciated.

like image 446
Ragunath Chilkuru Avatar asked Aug 17 '15 06:08

Ragunath Chilkuru


People also ask

How to handle Compound class name in selenium?

Selenium does not support BY. CLASS_NAME with compound class..you need to use cssSelector or XPath to find el3 here...

How do you write cssSelector in selenium?

Type “css=input[type='submit']” (locator value) in Selenium IDE. Click on the Find Button. The “Sign in” button will be highlighted, verifying the locator value. Attribute: Used to create the CSS Selector.

What is invalid selector exception in selenium?

The invalid selector error is a WebDriver error that occurs when an element retrieval command is used with an unknown web element selector strategy. The available selector strategies are CSS, link text, partial link text, tag name, and XPath. Any other selector strategy is rejected with this error.


1 Answers

You can access the element if it has multiple classes using "By":

from selenium.webdriver.common.by import By driver.findElement(By.cssSelector(".alert.alert-success")); 
like image 100
Juhi Saxena Avatar answered Sep 24 '22 18:09

Juhi Saxena