Python + Selenium: get span value from “ng-bind”

你说的曾经没有我的故事 提交于 2020-12-10 11:57:29

问题


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!


回答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!




回答2:


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.



来源:https://stackoverflow.com/questions/54693539/python-selenium-get-span-value-from-ng-bind

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!