我在Python中使用Selenium。我想得到.val()一个<select>元素,并检查它是我期望的。这是我的代码:def test_chart_renders_from_url(self): url = 'http://localhost:8000/analyse/' self.browser.get(url) org = driver.find_element_by_id('org') # Find the value of org?我怎样才能做到这一点?Selenium文档似乎有很多关于选择元素但没有关于属性的内容。
3 回答

一只甜甜圈
TA贡献1836条经验 获得超5个赞
你可能正在寻找get_attribute()。一个例子示此处以及
def test_chart_renders_from_url(self):
url = 'http://localhost:8000/analyse/'
self.browser.get(url)
org = driver.find_element_by_id('org')
# Find the value of org?
val = org.get_attribute("attribute name")

幕布斯7119047
TA贡献1794条经验 获得超8个赞
蟒蛇
element.get_attribute("attribute name")
Java的
element.getAttribute("attribute name")
红宝石
element.attribute("attribute name")
C#
element.GetAttribute("attribute name");
添加回答
举报
0/150
提交
取消