質問

I used pagefactory mode, and in my bean file, i declare the WebElement by using xpath:

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

and in my factory file(this class extends the bean class), i used

nextPage.getAttribute("class") 

but the result return me a null or empty. i dont know why...I just want to get the class of the following html, to judge if this is a clickable link or a common text.

here is the html:

<a class="easyquery_paginglink" href='javascript:gotoPage("consumeRecord","consumeRecord",2)'>nextpage</a>
役に立ちましたか?

解決

Your XPath could be "//a[Text() = 'nextpage']" then use .getAttribute("class"); So:

IWebElement element = _driver.FindElement(By.XPath("//a[Text() = 'nextpage']"));
string className = element.GetAttribute("class");
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top