Using C# and Selenium when I am trying to find an element on the page I keep getting this error
OpenQA.Selenium.NoSuchElementException: 'no such element: Unable to locate element: {"method":"xpath","selector":"//table[@id='ctl00_MainContent_gvMyProviders_ctl00']"}
I have tried
driver.FindElement(By.XPath
driver.FindElement(By.Id
I am using driver.FindElement(By.XPath in the initial login page to pass username, password and click submit
any help would be fantastic
Tuhin PaulPosted Sep 20, 2026, 10:35 AM
Most likely, the element isn't available in the DOM at the time Selenium searches for it. Since you're navigating through a login page, the page may still be loading or the element may be inside an iframe.
Wait for the element instead of searching immediately:var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
var table = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("ctl00_MainContent_gvMyProviders_ctl00")));Sam HobbsPosted Sep 18, 2026, 9:18 PM
There are multiple reasons it might not be working, such as;
The element is inside an iframe
The element isn't rendered yet
Case sensitivity / whitespace
You can open DevTools → Console and run your querySelector or something else there to determine if it works.
Also in DevTools you can click the arrow/inspect icon then click the desired element on the page. It gets highlighted in the Elements panel, and you can right-click it → Copy → Copy XPath (or Copy selector for CSS, or Copy full XPath). If a selector works in the console but not your program then that confirms it's an iframe or timing problem, not a selector problem.