简体   繁体   中英

Getting empty value when using “getAttribute()”

I'm trying to get the text "Lior Pelet", but i'm getting empty string

This is the site code:

<div class="crm-entity-stream-content-detail"><span>Lior Pelet</span></div>

And this is my code:

@FindBy(css=".crm-entity-stream-content-detail > span")
public WebElement txtFullName;  //full name 

String sContactName=txtFullName.getAttribute("span");

You can fetch by using getText() method instead of using the getAttribute() method.
You can do it like:

@FindBy(css=".crm-entity-stream-content-detail > span")
public WebElement txtFullName;  //full name 

String sContactName=txtFullName.getText();

OR

You can get the desired output by using getAttribute("value") .
You can do it like:

@FindBy(css=".crm-entity-stream-content-detail > span")
public WebElement txtFullName;  //full name 

String sContactName=txtFullName.getAttribute("value");
css=".crm-entity-stream-content-detail > span

means your "txtFullName" already is a span element, so call getText() method instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM