Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python + Selenium: get span value from "ng-bind"

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!

like image 846
Aaron Jonk Avatar asked Sep 05 '25 21:09

Aaron Jonk


2 Answers

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!

like image 193
Ratmir Asanov Avatar answered Sep 09 '25 20:09

Ratmir Asanov


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.

like image 33
KunduK Avatar answered Sep 09 '25 18:09

KunduK