0

I am facing an issue during some of my Selenium automation scripts (appears to be happening randomly) where an element that has already been interacted with is throwing an exception later in the test execution (not sure how or why).

For example, there is a method called 'Login()' which will send keys to a username field, send keys to the password field and then click the login button.

The login is a success, however, the locator associated with the username input will cause the test to fail after the specified timeout period (30 seconds) with the below -

'-> error: Element with locator: 'By.Id: username' wasn't visible within timeout limit'

When checking locally, the underlying error is 'NoSuchElementException', however, the element has already been interacted with.

It was suggested that the issue might have been that the errors I am seeing in my test were from the previous test run, however, this does not seem to be the case.

I tried updating the chrome driver version from 75.0.3770.8 to 75.0.3770.90 on the off chance that it may have been a bug, but that did not resolve the issue.

It has been very hard to replicate on my local machine, maybe happening once in every 20 tests, and the exception does not really give me anything to go on.

This is the first time I have seen this problem in my tests, and nothing has changed from a technology standpoint so I am at a bit of a loss as to what is going on here.

public void Login(SomeUser user)
{
    this.Username.SendKeys(user.Username);
    this.Password.SendKeys(user.Password);
    this.Login.Click();
}

The last action before the test fails is (as you can see) a button click, so i find it extremely odd that the username interaction should cause any issues.

The test execution is not parallel so i can't point it to any threading issue.


Test Name:  
Test FullName:  ....Tests.Stories..
Test Source:    C:\\\\\src\...\Tests\Stories\.feature : line 36
Test Outcome:   Failed
Test Duration:  0:01:17.326

Result StackTrace:  
at ...Core.Utilities.Wait.ForElementToBeVisible(By elementLocator, Int32 timeout) in C:\\\Shared\...Core\Utilities\Wait.cs:line 96
   at ...Core.Extensions.ElementLocatorExtensions.SendKeysWithWait(By elementLocator, String text) in C:\\\Shared\...Core\Extensions\ElementLocatorExtensions.cs:line 147
   at ....Pages.Executors.LoginPage.Login(String userId) in C:\\\\\src\...\Pages\Executors\LoginPage.cs:line 12
   at ....Tests.Steps.LoginSteps.GivenIAmLoggedInAsCustomer(String id) in C:\\\\\src\...\Tests\Steps\LoginSteps.cs:line 16
   at lambda_method(Closure , IContextManager , String )
   at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(IContextManager contextManager, StepInstance stepInstance)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep()
   at TechTalk.SpecFlow.TestRunner.CollectScenarioErrors()
   at ....Tests.Stories..ScenarioCleanup()
   at ....Tests.Stories..() in C:\\\\\src\...\Tests\Stories\.feature:line 41
--WebDriverTimeoutException
   at OpenQA.Selenium.Support.UI.DefaultWait`1.ThrowTimeoutException(String exceptionMessage, Exception lastException)
   at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
   at ...Core.Utilities.Wait.ForElementToBeVisible(By elementLocator, Int32 timeout) in C:\\\Shared\...Core\Utilities\Wait.cs:line 92
--NoSuchElementException
   at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementById(String id)
   at OpenQA.Selenium.By.<>c__DisplayClass16_0.<Id>b__0(ISearchContext context)
   at OpenQA.Selenium.By.FindElement(ISearchContext context)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)
   at SeleniumExtras.WaitHelpers.ExpectedConditions.<>c__DisplayClass7_0.<ElementIsVisible>b__0(IWebDriver driver)
   at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
Result Message: 
OpenQA.Selenium.WebDriverTimeoutException : Element with locator: 'By.Id: username' wasn't visible within timeout limit
  ----> OpenQA.Selenium.WebDriverTimeoutException : Timed out after 30 seconds
  ----> OpenQA.Selenium.NoSuchElementException : no such element: Unable to locate element: {"method":"css selector","selector":"#username"}
  (Session info: chrome=75.0.3770.100)
Result StandardOutput:  
Given I am logged in as a 'NoWarningCode' customer
-> error: Element with locator: 'By.Id: username' wasn't visible within timeout limit
  • Update the question with the trace logs – undetected Selenium Jun 26 '19 at 11:13
  • I will suggest adding some kind of waitUntil solution, we dont know what is going on your site, are there some kind of loaders etc. Check out this stack: [https://stackoverflow.com/questions/6992993/selenium-c-sharp-webdriver-wait-until-element-is-present](https://stackoverflow.com/questions/6992993/selenium-c-sharp-webdriver-wait-until-element-is-present) – Jacek Ratajewski Jul 26 '19 at 10:54

0 Answers0