-1

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");
Lior p
  • 45
  • 6
  • Possible duplicate of [How to use @FindBy annotation in Selenium for span text?](https://stackoverflow.com/questions/47860816/how-to-use-findby-annotation-in-selenium-for-span-text) – Ali Ben Zarrouk Oct 23 '19 at 11:59
  • there is no attribute called span in your html, why would you assume this to work? – f1sh Oct 23 '19 at 12:01

2 Answers2

2

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");
Sameer Arora
  • 4,439
  • 3
  • 10
  • 20
0
css=".crm-entity-stream-content-detail > span

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

Aykhan
  • 483
  • 5
  • 12