0

I would like to recieve the "text" contained in all the <div class='wld' text >. I tried this code :

match_results = driver.find_elements(By.CSS_SELECTOR, ".wld").text
 
print(match_results)

and this

  match_results = driver.find_elements(By.CSS_SELECTOR, ".wld")
     
    print(match_results.text)

and as well try the methods answered this question How to get text with selenium web driver in python that resemble the method that I did more high.

I get this error message :

 match_results = driver.find_elements(By.CSS_SELECTOR, ".wld").text
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'text'

and this

print(match_results.text)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'text'

When I Remove .text here is what this

[<selenium.webdriver.remote.webelement.WebElement (session="409c9b33d38ef268b14fe6f18992b61c", element="2321a252-8cb9-4fd1-8f8a-af837c28b35c")>,

and this for each element "text" contained in <div class='wld' text > What can I do for display all the "text", method to used ? I'm heard that it would have to through BeautifulSoup in others forum, your notice ?

Important information that I forgeted of precis : it is that I arrive to access the first element of way individual with method driver.find_element(By.CSS_SELECTOR, ".wld").text for exemple and.

the star
  • 259
  • 1
  • 2
  • 10

1 Answers1

1

'find_elements' method will return a list of elements and it does not have 'text' attribute.

So if you want to get list of elements try this.

match_results = driver.find_elements(By.CSS_SELECTOR, ".wld")
for elem in match_results:
   print(elem.text)

Or if you want to get only one element try this.

match_results = driver.find_element(By.CSS_SELECTOR, ".wld").text
Maran Sowthri
  • 829
  • 6
  • 14