如何获取Python + Selenium中元素的值? [英] How to get the value of an element in Python + Selenium?

查看:53
本文介绍了如何获取Python + Selenium中元素的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Python(3.6.3)代码中有了这个HTML元素(当然是Selenium网络元素):

I have got this HTML element in my Python (3.6.3) code (as Selenium webelement of course):

<span class="ocenaCzastkowa masterTooltip" style="color:#000000;" alt="Kod: 
pd1<br/>Opis: praca domowa<br/>Waga: 2,00<br/>Data: 12.09.2017<br/>Nauczyciel: 
(NAME CENSORED)">5</span>

,我想在最后获取值(在这种情况下为5),我不知道如何获取.显然我不能使用 webelement.get_attribute(),因为我不知道该属性的名称.

and I want to get the value at the end (which is 5 in this case) and I have got no idea how to get it. obviously I can't use webelement.get_attribute() cause I don't know the name of the attribute.

推荐答案

尝试以下代码:

span_element = driver.find_element_by_css_selector(".ocenaCzastkowa.masterTooltip")
span_element.text # This will return "5".

PS:您也可以使用 span_element.get_attribute("value").

PS: Also you can use span_element.get_attribute("value").

希望它对您有帮助!

这篇关于如何获取Python + Selenium中元素的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆