2012-05-14 14 views
0

我用pagefactory模式,在我的豆文件,我通過使用XPath聲明WebElement的HTML屬性:selenium2.0 webelement不能得到

@FindBy(xpath ='//div[5]/div/div/dl/dd[4]') 
def public WebElement nextPage //nextpage 

,並在我廠的文件(這個類擴展豆類),我用

nextPage.getAttribute("class") 

但結果返回空或空。我不知道爲什麼...我只想得到以下html的類,以判斷這是一個可點擊的鏈接還是常見的文本。

下面是HTML:

<a class="easyquery_paginglink" href='javascript:gotoPage("consumeRecord","consumeRecord",2)'>nextpage</a> 
+0

這是我想你問:我_I使用Selenium的webdriver選擇頁面上的元素與XPath和希望得到它的類attribute._ 這是正確的嗎?如果是這樣,你可以發佈你得到的錯誤信息,你試圖獲得的元素的html源代碼和你當前的xpath代碼。 – Nashibukasan

+0

是的,這是問題。沒有錯誤消息顯示,只有空或空結果返回時,當我使用getAttribute(「類」)... – Fiona

+0

這是html nextpage Fiona

回答

1

你的XPath可以是 「//一個[文本()= '下一頁']」,然後使用.getAttribute( 「類」); 所以:

IWebElement element = _driver.FindElement(By.XPath("//a[Text() = 'nextpage']")); 
string className = element.GetAttribute("class");