Compound class names not allowed cannot have whitespace in class name use css selectors instead

Console prompts error : Compound class names not permitted

id is not static in every time of the send button. But class is same in every message window. you can see it by looking at this (from firebug console) and previous one.

driver.findElement(By.className("T-I J-J5-Ji aoO T-I-atl L3 T-I-JW")).click(); 
The given selector T-I J-J5-Ji aoO T-I-atl L3 T-I-JW is either invalid or does not result in a WebElement. The following error occurred: InvalidSelectorError: Compound class names not permitted 

Did you try to search for the id «:rx» ? (Your first example is missing the colon which is why I ask)

I tried it more, in every time it gives the same error, the id is dynamic. it changes. but class is same.

1 Answer 1

This is because the in the class name that you have used T-I J-J5-Ji ao0 T-I-atl T-I-JW ,

are all different classes. When you use the following

driver.findElement(By.className("T-I J-J5-Ji ao0 T-I-atl T-I-JW")); 

the spaces between the class name confuses the method as to which class it should look for.

package testPkg; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class Gmail < public static void main(String[] args) < WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.get("https://www.google.lk/"); driver.findElement(By.linkText("Gmail")).click(); String s= driver.getTitle(); System.out.println(s); driver.findElement(By.id("Email")).sendKeys("xyz@gmail.com"); driver.findElement(By.id("next")).click(); driver.findElement(By.id("Passwd")).sendKeys("password"); driver.findElement(By.id("signIn")).click(); String s1= driver.getTitle(); System.out.println(s1); WebDriverWait wait= new WebDriverWait(driver,30); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[contains(text(),'COMPOSE')]"))); driver.findElement(By.xpath("//div[contains(text(),'COMPOSE')]")).click(); driver.findElement(By.xpath("//div[contains(text(),'Send')]")); driver.quit(); // TODO Auto-generated method stub >> 

Code tested on Ubuntu machine and working perfectly. The above code doesn’t take into account adding the email address of the recipient and the message body.

Источник

Selenium Compound class names not permitted

. implies that locator strategies using Compound class names are not valid while using Selenium., Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers ,How to locate an element with multiple classnames using Selenium and Python,Stack Overflow en español

Leon’s comment leads to the correct information that compound class names are no longer supported. What you could do instead is try using css selectors. In your case, the following line of code should help you get the element you want :

el3 = driver.find_element_by_css_selector(".action-btn.cancel.alert-display") 

It finds the element with all three classes (action-btn, cancel and alert-display) in the class attribute. Do note that the order of the classes does not matter here and any of the classes may appear anywhere in the class attribute. As long as the element has all three classes, it will be selected. If you want the order of the classes to be fixed, you can use the following xpath :

el3 = driver.find_element_by_xpath("//*[@class='action-btn cancel alert-display']") 

Answer by Dexter Avery

Exception in thread «main» org.openqa.selenium.InvalidSelectorException: invalid selector: Compound class names not permitted, Compound class names not permitted ,35327/compound-class-names-not-permitted,Exception handling in java

Читайте также:  Syntax for function php

This is the code I am using:

driver.get("https://www.coupondunia.in/"); driver.findElement(By.id("header-search-input")).sendKeys("Paytm",Keys.ENTER); Thread.sleep(3000); driver.findElement(By.className("fa fa-angle-right filter-icon filter-dropdown-category")).click(); 

Answer by Aubree Acosta

The issue is because of the way find by Class name works.,If the class name has space you’ll get the above error. You can simply get rid of the issue by using Id, CSS, Xpath, regular expression or any other element finder method.,in your code class name is textbox»,Suppose you have classname of input id such as:

While trying to access web element wherein the element’s class name have spaces in between.

driver.findElement(By.className("username textbox ")).sendKeys("123");;//compound class names not permitted 

Suppose you have classname of input id such as:

you have to use like this: .username.textbox .eg.

driver.findElement(By.cssSelector(".username.textbox")).sendKeys("123"); 
driver.findElement(By.className("partialclassname")); 

Answer by Langston Stevens

2021 Community Moderator Election , 2021 Community Moderator Election Results ,Asking for help, clarification, or responding to other answers.,Software Recommendations

This is because the in the class name that you have used T-I J-J5-Ji ao0 T-I-atl T-I-JW ,

are all different classes. When you use the following

driver.findElement(By.className("T-I J-J5-Ji ao0 T-I-atl T-I-JW")); 
package testPkg; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class Gmail < public static void main(String[] args) < WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.get("https://www.google.lk/"); driver.findElement(By.linkText("Gmail")).click(); String s= driver.getTitle(); System.out.println(s); driver.findElement(By.id("Email")).sendKeys("[email protected]"); driver.findElement(By.id("next")).click(); driver.findElement(By.id("Passwd")).sendKeys("password"); driver.findElement(By.id("signIn")).click(); String s1= driver.getTitle(); System.out.println(s1); WebDriverWait wait= new WebDriverWait(driver,30); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[contains(text(),'COMPOSE')]"))); driver.findElement(By.xpath("//div[contains(text(),'COMPOSE')]")).click(); driver.findElement(By.xpath("//div[contains(text(),'Send')]")); driver.quit(); // TODO Auto-generated method stub > > 

Answer by Jacob Calderon

my Error that i’m getting is: Message: invalid selector: Compound class names not permitted,Using find_element_by_class_name() you won’t be able to pass multiple class names. Passing multiple classes you will face the error as: Message: invalid selector: Compound class names not permitted ,Leon’s comment leads to the correct information that compound class names are no longer supported. What you could do instead is try using css selectors. In your case, the following line of code should help you get the element you want :,The problem is that i tried to do same thing on python but it doesnt work for me..

I was able to do it via Javascript from the Console tab i did it this way

recived_msg = document.getElementsByClassName('XELVh selectable-text invisible-space copyable-text') // returns an array of the chat recived_msg[5].innerText // shows me the 4th message content 
from selenium import webdriver recived_msg = driver.find_element_by_class_name('XELVh selectable-text invisible-space copyable-text') final = recived_msg[5].innerText #doesnt work for some reason 

Answer by Aliya Allison

selenium — Using the whitespace webdriver class name of Java , java — Error in webdriver that does not support compound class names , python — Selenium compound class names are not allowed , What characters are allowed in the C class name?

Читайте также:  Mapping programs in java

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")); 
 
Success KeyLinks Updated Successfully
REST Invocation Success

Источник

Compound class names not permitted error Webdriver

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")); 

Solution 2

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

As right now selenium doesn’t support multiple class name.If your class name includes a space, WebDriver will see it as a «compound selector». You can use cssSelector or id for selecting the webelement.

Solution 3

If usage of class name is must you can use the following ways:

1) css selectors:

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

2) using xpath

driver.findElement(By.xpath("//div[@class='alert alert-success']")) 

Try avoiding xpath and use css selectors instead.

Solution 4

It can also be done using class name like:

driver.find_element_by_class_name("alert") 
driver.find_element_by_class_name("alert-success") 

you can select anyone class name from two or more class names separated by spaces it’ll work just fine.

Solution 5

The issue is because of the way find by Class name works.

in your code class name is class=»alert alert-success»

If the class name has space you’ll get the above error. You can simply get rid of the issue by using Id, CSS, Xpath, regular expression or any other element finder method.

Do you need to use Class Name or can you use another method? Let me know if you need to use class name.

Источник

Not able To click in selenium browser with C#

You can try this: And Question: I am trying to enter a value to a «id class» but im getting error «Compound class names not permitted» I have alreay tried cssSelector and i get Unable to locate element Could you guys please help me? Also try using class names as multiple objects will have the same class name.

Not able To click in selenium browser with C#

I want to click this Button using code, try to click on Button By ClassName.

My code is as per below but not get any success.

string url1 = "myUrl"; IWebDriver driver = new ChromeDriver(Application.StartupPath); driver.Navigate().GoToUrl(url1); driver.FindElement(By.ClassName("wpcf7-form-control .wpcf7-submit btn solid")).Click(); 

This throws the following error :

Compound class names not allowed. Cannot have whitespace in class name. Use CSS selectors instead. and not use single class because there is a other class with same name.

driver.FindElement(By.XPath("//input[@type='submit']")).Click(); 

I would try to avoid using XPath, Instead I would add an Id to your input. The reason being XPath is more likely to be changed over time than Id. Also if you add another element with the same HTML, selenium will not be able to differentiate between them and will always select the first element. Using Id also makes your code more readable. You can try this:

 driver.FindElement(By.Id("YourButtonId")).Click(); 

Python: Message: invalid selector: Compound class names not, When you trying to locate elements using class names you cannot use multiple class names which you are getting the error.

Читайте также:  Tesseract ocr python pdf

Compound class names not permitted»

In this video we are going to discuss about How to Resolve «InvalidSelectorException invalid Duration: 5:20

How to fix compound class names not permitted error

This tutorial covers topic on className locator in selenium WebDriver. It covers simple Duration: 12:00

Selenium Webdriver Compound class names not permitted error

I am trying to enter a value to a «id class» but im getting error

«Compound class names not permitted»

I have alreay tried cssSelector and i get Unable to locate element

Could you guys please help me?

Try the following options:

"//input[@name='From']" "//input[@class='txtText'][@name='From']" 
"input[name=From]" "input.txtText[name=From]" 
driver.findElement(By.xpath("//input[@placeholder='Airport or City']")); 

Invalid selector: Compound class names not permitted error using, I am trying to print one of my messages from a chat via webWhatsapp. The problem is that i tried to do same thing on python but it doesnt work

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.

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.

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']"); 

You can use one of these class names, for example

if it can’t help you then you should switch to use other type of selector :css or :xpath

But note that in case of :css you write:

:xpath => '//div[@class='country code'] 

If you have class names which have spaces in them you will get this error. One way of avoiding is creating an xpath for identifying the element. If you show the html I can create the xpath. Also try using class names as multiple objects will have the same class name.

Selenium — compound class names not permitted, Try with xpath: theButtons = browser.find_elements_by_xpath(«//*[contains(@class,’Icon Icon—medium Icon—reply’)]»);.

Источник

Оцените статью