Question: I'm trying to parsing text from this html code using Selenium with python:

```
    <div class="  card card_selected" data-id="3248846777">
        <p>Hello World!</p>
    </div>

```

I use this code:

```
my_class = "  card card_selected"
live_deal = browser.find_element_by_class_name(my_class)

```

I get this error :

```
selenium.common.exceptions.InvalidSelectorException: Message: Given css selector expression ".  card card_selected" is invalid: InvalidSelectorError: '.  card card_selected' is not a valid selector: ".  card card_selected"

```

This error happen when the class name start with spaces.

how can I handle this error ?

Answer: 
```
browser.find_element_by_css_selector('[class|=" "]')

```

See more details here: <https://www.w3schools.com/css/css_attribute_selectors.asp>

> 
> **CSS `[attribute|="value"]` Selector**  
> 
>  The `[attribute|="value"]` selector is
>  used to select elements with the specified attribute starting with the
>  specified value.
> 
> 
>
Might be easier to use xpath contains() function

```
//div[contains(@class,'card_selected')]

```