-1

So far all my tests are running ok, to improve speed I was trying to run all in headless mode, but a bunch of those tests are failing, one of those had the following error:

  OpenQA.Selenium.ElementNotInteractableException: element not interactable
      (Session info: headless chrome=87.0.4280.141)
  Rastreamento de Pilha: 
    RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
    RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary'2 parameters)
    RemoteWebElement.Execute(String commandToExecute, Dictionary'2 parameters)
    RemoteWebElement.Click()

The line that returned that error is

Driver.FindElement(By.CssSelector("#page_content_inner > div.uk-grid > div > div:nth-child(2) > div > div > div > ul > li:nth-child(2) > a")).Click();

Other ones had click intercepted:

      (Session info: headless chrome=87.0.4280.141)
  Rastreamento de Pilha: 
    RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
    RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary'2 parameters)
    RemoteWebElement.Execute(String commandToExecute, Dictionary'2 parameters)
    RemoteWebElement.Click()

The line that generated the error is:

Driver.FindElement(By.Id("ClientesConvenio")).Click();

My true question is: Is there any limitations to headless mode? is there any beginners knowledge that I should have to use headless mode? why is this happening?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Not a solution, but issues where headless mode behaves differently from the full browser are quite common. Generally speaking the solution we use is to simplify the selectors, ideally by updating the underlying application to expose easy to target 'data-' attributes. Complex CSS selectors are very brittle, and need constant updating as the app changes. Using targets specific to tests will lead to more robust tests. – Nick Bailey Jan 25 '21 at 19:59

1 Answers1

1

As @Nick Bailey mentioned in his comments at times ...headless mode behaves differently from the full browser... due to:


Solution

Ideally to Click() on the element you have to induce WebDriverWait for the ElementToBeClickable() and you can use either of the following Locator Strategies:

  • Id:

    new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.Id("ClientesConvenio"))).Click();
    
  • CssSelector:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("#page_content_inner > div.uk-grid > div > div:nth-child(2) > div > div > div > ul > li:nth-child(2) > a"))).Click();
    

References

You can find a couple of relevant detailed discussion in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352