8

I'm trying to parse some html using Selenium. The problem is that it raises error in case the class name contains spaces.

Here is the tag I'm searching for: <p class="p0 ng-binding">text</p>

I've tried these two options:

result.find_element_by_class_name('departure').find_element_by_css_selector('p.p0 ng-binding').text 

result.find_element_by_class_name('departure').find_element_by_class_name('p0 ng-binding').text 

>>> selenium.common.exceptions.InvalidSelectorException: Message: The given selector p0 ng-binding is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: Compound class names not permitted

Could anybody give me a hint?

2
  • That's two class names. Commented Jun 20, 2015 at 12:01
  • An do you know how to find the class? Commented Jun 20, 2015 at 12:04

3 Answers 3

14

The p element has two classes: p0 and ng-binding.

Try this selector:

find_element_by_css_selector('p.p0.ng-binding')
Sign up to request clarification or add additional context in comments.

Comments

2

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

CssSelector("[class*='p0 ng-binding']"); //or
CssSelector("[class='p0 ng-binding']");

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

Comments

2

As @eee pointed out, to check multiple classes in a CSS selector, join them with dots:

p.p0.ng-binding

The problem with that though is that ng-binding class is not a good choice to base your locator on. Instead, check the p0 class only:

p.p0

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.