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>

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top