Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing html using Selenium - class name contains spaces

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?

like image 785
Milano Avatar asked Jun 20 '15 11:06

Milano


People also ask

How do you write xpath for class with spaces?

XPath("//*[contains(@class,'right-body-2')]//td[contains(concat(' ',normalize-space(@class),' '), ' ac ')]/a/@href"));

Can Java class names have spaces?

A class name is an identifier—a series of characters consisting of letters, digits, underscores ( _ ) and dollar signs ( $ ) that does not begin with a digit and does not contain spaces.

How do you get Textcontent in selenium?

New Selenium IDE It ignores the trailing and leading spaces. First of all we need to identify the element with help of any of the locators like id, class, name, xpath or css and then apply getText() method on it to get the text content of the element.

How do you select a button in selenium Python?

We can click a button with Selenium webdriver in Python using the click method. First, we have to identify the button to be clicked with the help of any locators like id, name, class, xpath, tagname or css. Then we have to apply the click method on it. A button in html code is represented by button tagname.


1 Answers

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

Try this selector:

find_element_by_css_selector('p.p0.ng-binding')
like image 134
eee Avatar answered Sep 27 '22 22:09

eee