【发布时间】:2017-05-08 23:49:10
【问题描述】:
我正在使用 Selenium 和 Splinter 为我的 Web 应用程序运行 UI 测试。我正在为页面上的视图生成一个随机 ID,并希望选择随机 ID 进行测试。
这是我正在使用的代码
from selenium import webdriver
from splinter import Browser
executable_path = {'executable_path':'./chromedriver.exe'}
browser = Browser('chrome', **executable_path)
data_view_id = browser.find_by_xpath('//ul[@class="nav"]').find_by_xpath('.//a[@href="#"]')[0].get_attribute("data-view-id")
# I am trying to get the id for the first item in the nav list and use it elsewhere
print(data_view_id)
这是我收到的错误:
AttributeError: 'WebDriverElement' object has no attribute 'get_attribute'
我查看了 WebElement 的“readthedocs”页面,它具有“get_attribute”值。我找不到任何关于 WebDriverElements 的文档,需要帮助来访问 WebElement
【问题讨论】: