1

Here is my element

<td>
<div class="linkButton" onclick="window.open('../../Report/Reports/ViewReport.aspx?reportName=Revenue.Report','Report1','scrollbars=1,resizable=yes,width=800,height=600');">Revenue Report</div>
</td>

I have tried the following XPaths:

//td[contains(text(), 'Revenue Report')]

//*[contains(@onclick, 'Revenue.Report')]

Both fail with "OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element"

Are there other options for selecting this web element?

1

There're usually more options, e.g.:

// CSS
currentDriver.FindElement(By.CssSelector("td > div.linkButton"));
currentDriver.FindElement(By.CssSelector("div.linkButton"));
// xPath
currentDriver.FindElement(By.XPath("//div[text()='Revenue Report']"));

Another problem might be with element visibility, you can search this site for more information on that. Selenium WebDriver with C# binding doesn't have any retry policy, so you basically need to wait for elements and their states.

1
//div[contains(text(), 'Revenue Report')]
//td[contains(string(), 'Revenue Report')]

use any of the above locator, the text is inside div tag and not td.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.