Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find_element_by_class_name class spaces does not work

I'm trying to use find_element_by_class_name where the class has spaces and it does not work:

Here is the code:

<a class="yt-simple-endpoint style-scope yt-formatted-string" href="/user/santanderbrasil">Santander Brasil</a>

I want the get the content "Santander Brasil"

I tried the following:

driver.find_element_by_class_name("yt-simple-endpoint.style-scope.yt-formatted-string")    
driver.find_element_by_class_name("a.yt-simple-endpoint.style-scope.yt-formatted-string")

and

driver.find_element_by_class_name("a.yt-simple-endpoint.")

none of the worked...

Any help?

like image 714
Fernão de Rocha Guerra Avatar asked Sep 01 '25 02:09

Fernão de Rocha Guerra


1 Answers

Use the css selector function instead.

driver.find_element_by_css_selector("a.yt-simple-endpoint.style-scope.yt-formatted-string")
like image 120
Grasshopper Avatar answered Sep 02 '25 16:09

Grasshopper