如何从 Selenium 获取元素的属性

2024-05-03

我正在 Python 中使用 Selenium。我想得到.val() of a <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 文档似乎有很多关于选择元素的内容,但没有关于属性的内容。


您可能正在寻找get_attribute()。显示了一个示例here http://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.get_attribute as well

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")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何从 Selenium 获取元素的属性 的相关文章

随机推荐