Parsing html using Selenium - class name contains spaces

I am trying to parse html using Selenium . The problem is that it throws an error if the class name contains spaces.

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

I 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

Can someone give me a hint?

+4
source share
3 answers

An element phas two classes: p0and ng-binding.

Try this selector:

find_element_by_css_selector('p.p0.ng-binding')
+3
source

As @eee pointed out, to test for multiple classes in the CSS selector , connect them with dots:

p.p0.ng-binding

, ng-binding . p0:

p.p0
+1

This problem. Invalid compound class names because the class name has several words that you can resolve using the css-selectors below

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

Hope this helps you. Go back if you have any questions.

0
source

All Articles