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"));
Selenium 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 :
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']")
Invalid selector: Compound class names not permitted error using Selenium
As per the documentation of selenium.webdriver.common.by
implementation:
class selenium.webdriver.common.by.By
Set of supported locator strategies.
CLASS_NAME = 'class name'
So,
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
Additionally, as you want to return an array of the chats, so instead of
find_element*
you need to usefind_elements*
Solution
As an alternative you can use either of :the following Locator Strategies:
CSS_SELECTOR
:recived_msg = driver.find_elements_by_css_selector(".XELVh.selectable-text.invisible-space.copyable-text")
XPATH
:recived_msg = driver.find_elements_by_xpath("//*[@class='XELVh selectable-text invisible-space copyable-text']")
InvalidSelector Error: compound class names not permitted using FindElementByClass
You need to take care of a couple of things here:
- The classnames of the
<span>
looks dynamic and and may change sooner or later, even may be next time you access the application afresh. - Selenium doesn't permit compund class names
Solution
To identify the element you can use the following locator strategies:
Using FindElementByCss:
bot.FindElementByCss("span[title='Customer']")
Using FindElementByXPath:
bot.FindElementByXPath("//span[@title='Customer' and text()='Customer']")
Compound class names not permitted in Selenium
You can just search for the pager__item--last
class - it uniquely identifies the element, given the HTML code you have presented:
driver.findElement(By.className("pager__item--last"));
Or, with a CSS selector:
driver.findElement(By.cssSelector(".pager__item--last"));
Or, making an exact class match:
driver.findElement(By.cssSelector("li[class='pager__item pager__item--last']"));
Findelement Run-time error '32' Compound Class names not permitted
Run-time error '32' message saying "Compound Class names not permitted
the error suggested that FindElementsByClass()
doesn't support multiple class names
it supports only class name
You can either pass single class only in FindElementsByClass()
or use FindElementByCss()
or FindElementByXPath()
Option 1:
Driver.FindElementsByClass("ui-button-text").Click
Option 2:
Driver.FindElementByCss(".ui-button-text.ui-clickable").Click
Option 3:
Driver.FindElementByXPath("//span[text()='Order Quotes']").Click
Related Topics
How to Read the Rgb Value of a Given Pixel in Python
Remove and Replace Printed Items
How to Quantify Difference Between Two Images
What Exactly Is File.Flush() Doing
How to Ignore Deprecation Warnings in Python
Why am I Getting Attributeerror: Object Has No Attribute
Pyaudio Working, But Spits Out Error Messages Each Time
How to Use Argsort in Descending Order
Python Numpy Valueerror: Operands Could Not Be Broadcast Together with Shapes
Python Multithreading Wait Till All Threads Finished
How to Plot Multiple Seaborn Jointplot in Subplot
How to Check If Two Segments Intersect
How to Update/Upgrade Pip Itself from Inside My Virtual Environment
How to Count Occurrence of Unique Values Inside a List
How to Scroll the Background Surface in Pygame
Add a String Prefix to Each Value in a String Column Using Pandas