SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
29.74k stars 8.02k forks source link

[🐛 Bug]: visual studio Bug: senenium in headless mode : "--headless=new" cant swich to a new window tab and recognize Xpath web element #14113

Closed BenSella closed 3 weeks ago

BenSella commented 3 weeks ago

What happened?

" senenium in headless mode : (options.AddArgument("--headless=new")) cant swich to a new window tab and recognize Xpath web element " Environment Microsoft Visual Studio Enterprise 2022 (2) (64-bit) – Current Version 17.9.3 Project: automation c# DotNet 8.0

Packages: "NUnit" Version="3.14.0"

"NUnit.Analyzers" Version="3.9.0"

"NUnit3TestAdapter" Version="4.5.0"

"Selenium.Support" Version="4.21.0"

"Selenium.WebDriver" Version="4.21.0"

"Selenium.WebDriver.ChromeDriver" Version="125.0.6422.6000"

Note that other attempted solutions did not work... css, Javascript borrowed for a temporary solution for example:

string cssSelector = "mat-card.mat-card.mat-focus-indicator.card:nth-of-type(1)";
Thread.Sleep(5000);
var iWebElement = _driver.FindElement(By.CssSelector(cssSelector))

How can we reproduce the issue?

here is the code I use to switch to a new tab (witch works perfectly in normal automation non headless mode)
"

        private void UrlAdressSmokeTest(bool generateNewChrome, IWebElement element, string urlFromAppsettings, WebDriverWait wait, int sleep, RegistriesHomePage page, By by)

        {

            element.Click();

            if (!generateNewChrome)

            {

                string originalWindow = _driver.CurrentWindowHandle;

                wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(20));

                wait.Until(driver => _driver.WindowHandles.Count > 1);

                var allWindows = _driver.WindowHandles;

                string newWindow = allWindows.FirstOrDefault(handle => handle != originalWindow);

                if (newWindow != null)

                {

                    _driver.SwitchTo().Window(newWindow);

                    if (by != null)

                    {

                        try

                        {

                            IWebElement visableEelement = wait.Until(ExpectedConditions.ElementIsVisible(by));

                        }

                        catch (Exception ex)

                        {

                            LogToAllure(false, $"could not fined element{by}\non page :{urlFromAppsettings} ");

                        }

                    }

                    else

                    {

                        Thread.Sleep(sleep);

                    }

                    string receavedUrl = _driver.Url;

                    CompareUrl(urlFromAppsettings, receavedUrl);

                    _driver.Close();

                    _driver.SwitchTo().Window(originalWindow);

                }

                else

                {

                    throw new Exception("New window was not found.");

                }

            }

            else

            {

                try

                {

                    IWebElement visableEelement = wait.Until(ExpectedConditions.ElementIsVisible(by));

                }

                catch (Exception ex)

                {

                    LogToAllure(false, $"could not fined element{by}\non page :{urlFromAppsettings}\nerror message: {ex} ");

                }

                receavedUrl = _driver.Url;

                CompareUrl(urlFromAppsettings, receavedUrl);

                IWebElement getBackToHomePage = _driver.FindElement(page.ReturToHomePageButton());

                getBackToHomePage.Click();

            }

        }
"

Relevant log output

OpenQA.Selenium.WebDriverTimeoutException: 'Timed out after 20 seconds'

NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"(//mat-card[@class='mat-card mat-focus-indicator card'])[1]"}

  (Session info: chrome=125.0.6422.142); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception

Operating System

windows 10

Selenium version

4.21.0

What are the browser(s) and version(s) where you see this issue?

Chrom Version 125.0.6422.142 (Official Build) (64-bit)

What are the browser driver(s) and version(s) where you see this issue?

Selenium.WebDriver.ChromeDriver" Version="125.0.6422.6000

Are you using Selenium Grid?

No response

github-actions[bot] commented 3 weeks ago

@BenSella, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

github-actions[bot] commented 3 weeks ago

Hi, @BenSella. This issue has been determined to require fixes in ChromeDriver.

You can see if the feature is passing in the Web Platform Tests.

If it is something new, please create an issue with the ChromeDriver team. Feel free to comment the issues that you raise back in this issue. Thank you.