0

That's it basically, when i run the app manually it runs fine, but when I run it with task scheduler it fails in the middle of application with the exception:

OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"*[name ="start_year"]"}

The strange part is, the program mostly works with the scheduler, it calls a few webapi before it fails, loads appsettings.json values, but when it is scheduled on windows (I tried with a few windows server and reproducable with windows 10 home as well), when Selenium loaded a site and logged in, than fails to find a dom element every time.

I tried to run with highest privileges, tried setting the run wether user not logged in in scheduler, I set the value of my app folder in task scheduler Start in textbox, it seems like no changes in task scheduler settings helps.

I using IHostBuilder and dependency injection with latest 4.8.0 Selenium.Support and Selenium.WebDriver nuget packages.

I using implicitwait and the following chromeoptions:

        var chromeOptions = new ChromeOptions
        {
            BinaryLocation = config["chromebinarypath"],
        };



            chromeOptions.AddArgument("--disable-extensions");// disabling extensions
            chromeOptions.AddArgument("--disable-gpu");// applicable to windows os only
            chromeOptions.AddArgument("--disable-dev-shm-usage");// overcome limited resource problems
            chromeOptions.AddArgument("--no-sandbox");// Bypass OS security model
            chromeOptions.AddArgument("--headless");// Bypass OS security model
        

        _chromeDriver = new ChromeDriver(chromeOptions);
        _chromeDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(180);
        //Important, enables waiting for dom objects till they available for 10 seconds.
        _chromeDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

Can someone point me to right direction?

Maybe it is some kind of Selenium bug? Maybe the issue is related to the used IHost, and I should just call the classes without dependecy injection?

deadsystem
  • 27
  • 5

1 Answers1

0

This error message...

OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"*[name ="start_year"]"}

...implies that the desired element wasn't visible within the HTML DOM while FindElement() was invoked.


Solution

Possibly you need to tweak the locator strategy a bit by removing the * from the css selector as follows:

driver.FindElement(By.CssSelector("[name ="start_year"]"));

As an alternative, you can also use By.Name as follows:

driver.FindElement(By.Name("start_year"));
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Sorry, but it does not answer the question. Stange enough Im not even use CssSelector, I use FindElement(By.Name(elementName), where the elementName is start_year in this case. Further testing revealed, It looks like click events not working when the program is scheduled by task scheduler. Somehow if I check the run when the user logged in checkbox in task scheduler, it works, but if I check the checkbox run wether the user logged in or not, than fails with this strange message, and cant log in. I think somehow the page cant receive focus when running in the background. – deadsystem Feb 02 '23 at 11:11