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?
2 Answers 2
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.
//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.
Explore related questions
See similar questions with these tags.