selenium2.0 webelement无法获取html的属性

时间:2012-05-14 02:20:09

标签: xpath selenium getattribute

我使用了pagefactory模式,在我的bean文件中,我使用xpath声明了WebElement:

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

在我的工厂文件中(这个类扩展了bean类),我使用了

nextPage.getAttribute("class") 

但结果返回null或空。我不知道为什么......我只是想得到以下html的类,判断这是一个可点击的链接还是一个普通文本。

这是html:

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

1 个答案:

答案 0 :(得分:2)

您的XPath可能是“// a [Text()='nextpage']”然后使用.getAttribute(“class”); 所以:

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