我正在使用Selenium和Splinter爲我的Web應用程序運行我的UI測試,我爲頁面上的視圖生成一個隨機ID,並且想要選擇隨機。ID爲測試Python Selenium「WebDriverElement」對象沒有屬性'get_attribute'
這裏是我使用
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)
這個代碼是我收到的錯誤:我已經看過了「readthedocs
AttributeError: 'WebDriverElement' object has no attribute 'get_attribute'
'WebElement的頁面,它具有'get_attribute'值。我找不到有關WebDriverElements的任何文檔,並且需要訪問WebElement的幫助來代替