I am trying to do some unit testing with selenium2 using the following code:
private const string TicketName = "Automated Test Ticket";
[Test]
public void EditTicketTest() {
var tableData = driver.FindElement(By.XPath("//td[contains(text(), '" + TicketName + "')]"));
}
The test fails with the following reason:
OpenQA.Selenium.NoSuchElementException : Unable to locate element: {"method":"xpath","selector":"//td[contains(text(), 'Automated Test Ticket')]"}
But when I look at the page and inspect the element, the text is definitely inside the tag. Is it possible that there is some excess spacing or something else that could be causing it to not recognize the text?
Here is the HTML:
<tr data-id="55">
<td>55</td>
<td class="ticket-title">
<span data-original-title="Automated Test Ticket" class="work-on-ticket-note-icon-tickets" data-toggle="tooltip" data-placement="right" data-trigger="hover" title=""></span> <span data-original-title="This is a work on ticket note for a company!" class="work-on-ticket-note-icon-companies" data-toggle="tooltip" data-placement="right" data-trigger="hover" title=""></span> Automated Test Ticket
</td>
<td>Medium</td>
<td>Active</td>
<td>8/25/2014<br> <small>(0 changes)</small></td>
<td><a href="#" class="modal-open" data-modal="company-details-modal" data-url="/companies/details/1"></a></td>
<td>
<strong class="text-danger">None Assigned</strong>
</td>
<td>
<a href="#" class="modal-open btn btn-sm btn-success" data-modal="edit-modal" data-url="/{controller}/edit/55"><span class="glyphicon glyphicon-edit"></span></a>
<a href="#" class="modal-open btn btn-sm btn-info" data-modal="log-modal" data-url="/{controller}/log/55"><span class="glyphicon glyphicon-list-alt"></span></a>
<a href="#" class="modal-open btn btn-sm btn-warning" data-modal="addtime-modal" data-url="/{controller}/addtime/55"><span class="glyphicon glyphicon-time"></span></a>
</td>
</tr>
NoSuchElementExceptionis usually because 1. The element you're trying to locate is in a<frame>or<iframe>, or 2. The element you're trying to locate is not yet displayed on the page when the attempt is made.