2017-05-08 23 views
1

WebアプリケーションのUIテストを実行するのにSeleniumとSplinterを使用しています。ページのビューのランダムIDを生成しています。 。Python Selenium "WebDriverElement"オブジェクトに 'get_attribute'属性がありません

AttributeError: 'WebDriverElement' object has no attribute 'get_attribute' 

私は "readthedocs見てきた:テストのための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) 

この

を使用していたコードです'ページには' get_attribute 'という値があります。 WebDriverElementsに関するドキュメントが見つかりません。代わりにWebElementにアクセスするためのヘルプが必要です

答えて

2

WebDriverElementはSeleniumではなく、Splinterからのものです。

はスプリンターでは、あなたが辞書のような属性にアクセス

data_view_id = browser.find_by_xpath('//ul[@class="nav"]').find_by_xpath('.//a[@href="#"]')[0]['data-view-id']

Splinter docsを参照)、またはあなたが望んでいた場合はセレンでそれを行うには:

browser.find_element_by_xpath('//ul[@class="nav"]').find_element_by_xpath('.//a[@href="#"]').get_attribute("data-view-id")

関連する問題