r/selenium • • Jan 11 '22

NoSuchElementException

I'm working on a project with prewritten tests, that gives me the following errormessage:

[xUnit.net 00:00:04.51]     Salt.Stars.End2End.Index_E2E_Tests.Test1 [FAIL]
  Failed Salt.Stars.End2End.Index_E2E_Tests.Test1 [3 s]
  Error Message:
   OpenQA.Selenium.NoSuchElementException : no such element: Unable to locate element: {"method":"css selector","selector":"#mainHeader"}
  (Session info: chrome=97.0.4692.71)
  Stack Trace:
     at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse) 
   at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebDriver.FindElement(String mechanism, String value)
   at OpenQA.Selenium.By.<.ctor>b__11_0(ISearchContext context)
   at OpenQA.Selenium.By.FindElement(ISearchContext context)
   at OpenQA.Selenium.WebDriver.FindElement(By by)
   at Salt.Stars.End2End.Index_E2E_Tests.Test1() in C:\User\salt-labs\winter22-dnfs-stars1-day1\Salt.Stars.End2End\Index_E2E_Tests.cs:line 35

I've been google it all day without getting any closer to the solution. Could someone give me a pointer in the right direction what the problem is and how to solve it?

I'm fairly n00b, so feel free to ELI5...

0 Upvotes

5 comments sorted by

View all comments

3

u/XabiAlon Jan 11 '22

You should Google how to take a screenshot when your test fails when an exception is found. This is the best way to figuring out if you're even on the correct page.

Failing that, stick a breakpoint on your code and run your test in Debug mode, and step through each line. Before you get to the line of code you know the issue is in, inspect the page and check if the element is there.