Question

I have tried with below code but nothing. i want to get Not Started.

String ExpectedlastActivity=driver.findElement(By.xpath("//*[@id='content']/div/div/div[1]/div/div[2]/div[2]/div/div[3]/div/table/tbody/tr[1]/td[2]/span/div/a")).getText();
    System.out.println("Last activity ");
    System.out.println(ExpectedlastActivity);

Here is HTML.

<span class="normal index" data-index="" data-fieldname="status">
<span class="edit" sfuuid="245">
<div id="s2id_autogen59" class="select2-container required" style="width: 100%;">
<a class="select2-choice" tabindex="-1" onclick="return false;" href="javascript:void(0)">
<span>Not Started</span>
<abbr class="select2-search-choice-close select2-display-none" style="display: none;"/>
<div>
</a>

Was it helpful?

Solution

Using a By.partialLinkText would work WAY better than that long By.xpath you defined. Anytime you are trying to get an anchor, always use By.partialLinkText (which uses xpath under the hood). Otherwise, your code looks ok to me.

OTHER TIPS

you can try cssSelectors as well,

String ExpectedlastActivity=driver.findElement(By.cssSelector("a.select2-choice > span")).getText();
System.out.println("Last activity ");
System.out.println(ExpectedlastActivity);

By Reviewing the Html I found two span tag before div so add one more span before div tag or post the link of webpage.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top