3

So I have Selenium code that goes to a page using chrome. Now at that page, there is this HTML;

<span ngbind="pageData.Message">Heloooo</span>

How can I get the value using python and Selenium? So only the Heloooo. Thanks!

Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
Aaron Jonk
  • 473
  • 2
  • 7
  • 21

2 Answers2

1

You can use the following CSS Selector for locating the element:

span[ngbind='pageData.Message']

Code:

element = driver.find_element_by_css_selector("span[ngbind='pageData.Message']")
print(element.text)  # Will print the "Heloooo" value.

Hope it helps you!

Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
1

You can try using XPath to get the text of the element:

element1 = driver.find_element_by_xpath("//span[@ngbind='pageData.Message']")
print(element1.text)

It's just another option.

Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
KunduK
  • 32,888
  • 5
  • 17
  • 41