euro euro - 5 months ago 56
HTML Question

Selenium WebDriver how to verify Text from Span Tag

I'm trying to verify the text in the span by using WebDriver. There is the span tag:

<span class="value">
/Company Home/IRP/tranzycja
</span>


I tried something like this:

driver.findElement(By.xpath("//span[@id='/Company Home/IRP/tranzycja']'"));
driver.findElement(By.cssSelector("span./Company Home/IRP/tranzycja"));


but none of this work.

Any help would be really appreciated. Thanks

More code:

<span id="uniqName_64_0" class="alfresco-renderers-PropertyLink alfresco-renderers-Property pointer small" data-dojo-attach-point="renderedValueNode" widgetid="uniqName_64_0">
<span class="inner" tabindex="0" data-dojo-attach-event="ondijitclick:onLinkClick">
<span class="label">
In folder:
</span>
<span class="value">
/Company Home/IRP/tranzycja
</span>
</span>


uniqName shouldn't be a target because are a lot of them and they are change.

There is a full html code:
http://www.filedropper.com/spantag

Answer

Here I am assuming you are trying to verify the text in the span tag.

i.e '/Company Home/IRP/tranzycja'

Try Below code

String expected String = "/Company Home/IRP/tranzycja";

String actual_String = driver.findElement(By.xpath("//span[@class='alfresco-renderers-PropertyLink alfresco-renderers-Property pointer small']//span[@class='value']")).getText();

if(expected String.equals(actual_String))

{

System.out.println("Text is Matched");

}

else

{

System.out.println("Text is not Matched");

}
Comments