-1

I have a following line of code:

<div class="topText">Text</div>

And i want to get "Text" from it as String variable MyText

I have tried to use this:

MyText = driver.find_element_by_xpath("string(//div[@class='topText'])")

But it gives me an error: Message: invalid selector: Unable to locate an element with the xpath expression string(//div[@class='topText_1SWFA']) because of the following error: TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type.

I have also tried simple Xpath like:

MyText = driver.find_element_by_xpath("//div[@class='topText_1SWFA']/text()")

or another alternatives but it doesn't work either

Ricrd
  • 1

1 Answers1

0
html = '<div class="topText">Text</div>'
soup = BeautifulSoup(html, 'html.parser')
finder = soup.find('div', class_='topText')
text = finder.getText()
Andrew Lt
  • 183
  • 1
  • 4