SeleniumHQ / selenium

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

[🐛 Bug]: Chrome not open in Windows Server 2022 (azure pipeline self hosted agent) via chromedriver.exe in .NET 6/8 app #14146

Closed frankechen closed 1 week ago

frankechen commented 1 week ago

What happened?

We are able to run selenium tests locally. Test project uses .NET 6, MSTest, Selenium WebDriver (4.21), Selenium.WebDriver.ChromeDriver (126.0.6478.6100). and we specify property WebDriverPlatform is win32 in project file.

The test fails to create chrome driver at agent. You can see log output below that I pick some logs from agent that Chrome 125 is in use. (Chrome auto update is enabled).

And we also try below:

Agent:

SimpleApp.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <WebDriverPlatform>win32</WebDriverPlatform>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Selenium.WebDriver" Version="4.21.0" />
    <PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="126.0.6478.6200" />
  </ItemGroup>
</Project>

program.cs

using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Internal.Logging;
using System.Net.NetworkInformation;

namespace SimpleApp
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
            Log.SetLevel(LogEventLevel.Trace);
            Log.Handlers.Add(new FileLogHandler(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log.txt")));
            CheckPorts();
            try
            {
                var options = new ChromeOptions();
                options.AddArgument("--incognito");
                options.AddArgument("--window-size=800,600");
                Console.WriteLine("create chrome options");
                var driver = new ChromeDriver(AppDomain.CurrentDomain.BaseDirectory, options);
                Console.WriteLine("create chrome driver");

                CheckPorts();
                driver.Navigate().GoToUrl("https://www.bing.com");
                Thread.Sleep(3000);

                driver.Dispose();
                Console.WriteLine("dispose chrome driver");
            }
            catch (Exception ex)
            {
                Console.WriteLine("catch error");
                Console.WriteLine(ex.Message);
                CheckPorts();
            }
            Console.WriteLine("the end");
        }

        static void CheckPorts()
        {
            var props = IPGlobalProperties.GetIPGlobalProperties();
            var points = props.GetActiveTcpListeners();
            Console.WriteLine(string.Join(",", points.Select(p => p.Port).Distinct().OrderBy(p => p)).ToArray());
        }
    }
}

### Relevant log output

```shell
MSTest Executor: Test Parallelization enabled for xxx.dll (Workers: 4, Scope: ClassLevel).
Starting ChromeDriver 125.0.6422.60 (3ac3319bff9f3e139d632e3d195e3d2d43d86e37-refs/branch-heads/6422@{#1017}) on port 52626
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Starting ChromeDriver 125.0.6422.60 (3ac3319bff9f3e139d632e3d195e3d2d43d86e37-refs/branch-heads/6422@{#1017}) on port 52727
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Starting ChromeDriver 125.0.6422.60 (3ac3319bff9f3e139d632e3d195e3d2d43d86e37-refs/branch-heads/6422@{#1017}) on port 52815
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Starting ChromeDriver 125.0.6422.60 (3ac3319bff9f3e139d632e3d195e3d2d43d86e37-refs/branch-heads/6422@{#1017}) on port 52897
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
##[error]The task has timed out.

Operating System

Windows Server 2022

Selenium version

.NET 6.0

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

Chrome 126

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

webdriver 4.21.0, chromedriver 126.0.6478.6100

Are you using Selenium Grid?

No

github-actions[bot] commented 1 week ago

@frankechen, 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 1 week ago

We need more information about this issue in order to troubleshoot.

Please turn on logging and re-run your code. Information on how to adjust logs for your language can be found in our Troubleshooting documentation.

frankechen commented 1 week ago
2024-06-19T02:04:26.4669414Z 2024-06-19 04:01:50.327 DEBUG HttpCommandExecutor: Executing command: []: quit {}
2024-06-19T02:04:26.4671969Z 2024-06-19 04:01:50.364 TRACE HttpCommandExecutor: >> Method: DELETE, RequestUri: 'http://localhost:50681/session/', Version: 1.1, Content: <null>, Headers:
2024-06-19T02:04:26.4673139Z {
2024-06-19T02:04:26.4674196Z }
2024-06-19T02:04:26.4676879Z 2024-06-19 04:01:51.131 TRACE HttpCommandExecutor: << StatusCode: 405, ReasonPhrase: 'Method Not Allowed', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
2024-06-19T02:04:26.4683299Z {
2024-06-19T02:04:26.4684102Z   Server: Microsoft-IIS/10.0
2024-06-19T02:04:26.4684802Z   Date: Wed, 19 Jun 2024 02:01:50 GMT
2024-06-19T02:04:26.4685480Z   Allow: GET, HEAD, OPTIONS, TRACE
2024-06-19T02:04:26.4686289Z   Content-Type: text/html
2024-06-19T02:04:26.4687094Z   Content-Length: 1293
2024-06-19T02:04:26.4687633Z }
2024-06-19T02:04:26.4689503Z 2024-06-19 04:01:51.139 DEBUG HttpCommandExecutor: Response: ( UnhandledError: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2024-06-19T02:04:26.4690757Z <html xmlns="http://www.w3.org/1999/xhtml">
2024-06-19T02:04:26.4691302Z <head>
2024-06-19T02:04:26.4692737Z <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
2024-06-19T02:04:26.4694226Z <title>405 - HTTP verb used to access this page is not allowed.</title>
2024-06-19T02:04:26.4695116Z <style type="text/css">
2024-06-19T02:04:26.4697186Z <!--
2024-06-19T02:04:26.4699631Z body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}
2024-06-19T02:04:26.4700713Z fieldset{padding:0 15px 10px 15px;}
2024-06-19T02:04:26.4703697Z h1{font-size:2.4em;margin:0;color:#FFF;}
2024-06-19T02:04:26.4705947Z h2{font-size:1.7em;margin:0;color:#CC0000;}
2024-06-19T02:04:26.4708213Z h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;}
2024-06-19T02:04:26.4710848Z #header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;
2024-06-19T02:04:26.4718524Z background-color:#555555;}
2024-06-19T02:04:26.4719320Z #content{margin:0 0 0 2%;position:relative;}
2024-06-19T02:04:26.4721719Z .content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}
2024-06-19T02:04:26.4722879Z -->
2024-06-19T02:04:26.4723433Z </style>
2024-06-19T02:04:26.4725539Z </head>
2024-06-19T02:04:26.4727337Z <body>
2024-06-19T02:04:26.4729540Z <div id="header"><h1>Server Error</h1></div>
2024-06-19T02:04:26.4731957Z <div id="content">
2024-06-19T02:04:26.4734436Z  <div class="content-container"><fieldset>
2024-06-19T02:04:26.4735996Z   <h2>405 - HTTP verb used to access this page is not allowed.</h2>
2024-06-19T02:04:26.4738193Z   <h3>The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access.</h3>
2024-06-19T02:04:26.4739563Z  </fieldset></div>
2024-06-19T02:04:26.4741937Z </div>
2024-06-19T02:04:26.4744067Z </body>
2024-06-19T02:04:26.4746119Z </html>
2024-06-19T02:04:26.4748140Z )
2024-06-19T02:04:26.4752232Z 2024-06-19 04:02:18.561 TRACE DriverService: System.Threading.Tasks.TaskCanceledException: The request was canceled due to the configured HttpClient.Timeout of 5 seconds elapsing.
2024-06-19T02:04:26.4754129Z  ---> System.TimeoutException: A task was canceled.
2024-06-19T02:04:26.4755486Z  ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
2024-06-19T02:04:26.4757180Z    at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)
2024-06-19T02:04:26.4759527Z    at System.Net.Http.HttpConnectionPool.GetHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
2024-06-19T02:04:26.4761439Z    at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
2024-06-19T02:04:26.4763530Z    at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
2024-06-19T02:04:26.4765985Z    at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
2024-06-19T02:04:26.4772498Z    --- End of inner exception stack trace ---
2024-06-19T02:04:26.4773674Z    --- End of inner exception stack trace ---
2024-06-19T02:04:26.4775342Z    at System.Net.Http.HttpClient.HandleFailure(Exception e, Boolean telemetryStarted, HttpResponseMessage response, CancellationTokenSource cts, CancellationToken cancellationToken, CancellationTokenSource pendingRequestsCts)
2024-06-19T02:04:26.4778092Z    at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
2024-06-19T02:04:26.4780184Z    at OpenQA.Selenium.DriverService.<>c__DisplayClass51_0.<<get_IsInitialized>b__0>d.MoveNext()
2024-06-19T02:04:26.4781595Z --- End of stack trace from previous location ---
2024-06-19T02:04:26.4782564Z    at OpenQA.Selenium.DriverService.get_IsInitialized()
titusfortner commented 1 week ago

Need to see more logs. There should be a session id as part of the delete command. What is going on before this?

You can put it all in a gist and share the link.

frankechen commented 1 week ago

Need to see more logs. There should be a session id as part of the delete command. What is going on before this?

You can put it all in a gist and share the link.

I update the reproduce steps for the issue above, you can check the SimpleApp.csproj and program.cs. Attach log content below for running SimpleApp at pipeline.

2024-06-19T04:08:55.5662940Z Hello, World!
2024-06-19T04:08:55.6134528Z 80,xxx
2024-06-19T04:08:55.6208572Z create chrome options
2024-06-19T04:08:56.1344161Z Starting ChromeDriver 126.0.6478.62 (b2781ca4c383af675f7a25c7b03b4a54e25e559a-refs/branch-heads/6478_56@{#4}) on port 54395
2024-06-19T04:08:56.1358998Z Only local connections are allowed.
2024-06-19T04:08:56.1364268Z Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
2024-06-19T04:08:56.1525073Z ChromeDriver was started successfully.
2024-06-19T04:09:16.3102914Z 06:09:16.299 DEBUG HttpCommandExecutor: Executing command: []: quit {}
2024-06-19T04:09:16.3238683Z 06:09:16.323 TRACE HttpCommandExecutor: >> Method: DELETE, RequestUri: 'http://localhost:54395/session/', Version: 1.1, Content: <null>, Headers:
2024-06-19T04:09:16.3245118Z {
2024-06-19T04:09:16.3245693Z }
2024-06-19T04:09:17.0871669Z 06:09:17.086 TRACE HttpCommandExecutor: << StatusCode: 405, ReasonPhrase: 'Method Not Allowed', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
2024-06-19T04:09:17.0873042Z {
2024-06-19T04:09:17.0873909Z   Server: Microsoft-IIS/10.0
2024-06-19T04:09:17.0876599Z   Date: Wed, 19 Jun 2024 04:09:16 GMT
2024-06-19T04:09:17.0877196Z   Allow: GET, HEAD, OPTIONS, TRACE
2024-06-19T04:09:17.0878175Z   Content-Type: text/html
2024-06-19T04:09:17.0878784Z   Content-Length: 1293
2024-06-19T04:09:17.0879128Z }
2024-06-19T04:09:17.0918663Z 06:09:17.091 DEBUG HttpCommandExecutor: Response: ( UnhandledError: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2024-06-19T04:09:17.0919990Z <html xmlns="http://www.w3.org/1999/xhtml">
2024-06-19T04:09:17.0920734Z <head>
2024-06-19T04:09:17.0921978Z <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
2024-06-19T04:09:17.0923387Z <title>405 - HTTP verb used to access this page is not allowed.</title>
2024-06-19T04:09:17.0929742Z <style type="text/css">
2024-06-19T04:09:17.0930654Z <!--
2024-06-19T04:09:17.0932141Z body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}
2024-06-19T04:09:17.0935491Z fieldset{padding:0 15px 10px 15px;} 
2024-06-19T04:09:17.0944184Z h1{font-size:2.4em;margin:0;color:#FFF;}
2024-06-19T04:09:17.0945546Z h2{font-size:1.7em;margin:0;color:#CC0000;} 
2024-06-19T04:09:17.0946668Z h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} 
2024-06-19T04:09:17.0948303Z #header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;
2024-06-19T04:09:17.0949457Z background-color:#555555;}
2024-06-19T04:09:17.0950128Z #content{margin:0 0 0 2%;position:relative;}
2024-06-19T04:09:17.0951558Z .content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}
2024-06-19T04:09:17.0952498Z -->
2024-06-19T04:09:17.0952929Z </style>
2024-06-19T04:09:17.0953345Z </head>
2024-06-19T04:09:17.0953774Z <body>
2024-06-19T04:09:17.0954295Z <div id="header"><h1>Server Error</h1></div>
2024-06-19T04:09:17.0954873Z <div id="content">
2024-06-19T04:09:17.0955722Z  <div class="content-container"><fieldset>
2024-06-19T04:09:17.0956817Z   <h2>405 - HTTP verb used to access this page is not allowed.</h2>
2024-06-19T04:09:17.0957840Z   <h3>The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access.</h3>
2024-06-19T04:09:17.0962452Z  </fieldset></div>
2024-06-19T04:09:17.0962910Z </div>
2024-06-19T04:09:17.0963315Z </body>
2024-06-19T04:09:17.0963739Z </html>
2024-06-19T04:09:17.0964150Z )
2024-06-19T04:09:38.2342523Z catch error
2024-06-19T04:09:38.2343331Z Cannot start the driver service on http://localhost:54395/
2024-06-19T04:09:38.2357512Z 80,xxx
2024-06-19T04:09:38.2360618Z the end

I have method that checks listening ports, 54395 is not found.

I also try to run chromedriver.exe manually at pipeline, see below:

netstat -aon | findstr /i listening
Start-Process .\chromedriver.exe -ArgumentList='--log-level=ALL --port=56789'
Start-Sleep -Seconds 5
netstat -aon | findstr /i listening

56789 is found when listing listening ports.

I check log.txt locally, it looks a bit different. Compared with log.txt at pipeline, it has log that creates session, has post request to create session id.

2024-06-19 11:23:11.065 DEBUG HttpCommandExecutor: Executing command: []: newSession {"capabilities":{"firstMatch":[{"browserName":"chrome","goog:chromeOptions":{"args":["--incognito","--window-size=800,600"]}}]}}
2024-06-19 11:23:11.079 TRACE HttpCommandExecutor: >> Method: POST, RequestUri: 'http://localhost:56867/session', Version: 1.1, Content: System.Net.Http.ByteArrayContent, Headers:
{
  Accept: application/json; charset=utf-8
  Content-Type: application/json; charset=utf-8
}
2024-06-19 11:23:11.769 TRACE HttpCommandExecutor: << StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Cache-Control: no-cache
  Content-Length: 885
  Content-Type: application/json; charset=utf-8
}
2024-06-19 11:23:11.801 DEBUG HttpCommandExecutor: Response: (3935f440fb9c568caa4de3c93b72f51c Success: System.Collections.Generic.Dictionary`2[System.String,System.Object])
2024-06-19 11:23:11.807 DEBUG HttpCommandExecutor: Executing command: [3935f440fb9c568caa4de3c93b72f51c]: get {"url":"https://www.bing.com"}
2024-06-19 11:23:11.808 TRACE HttpCommandExecutor: >> Method: POST, RequestUri: 'http://localhost:56867/session/3935f440fb9c568caa4de3c93b72f51c/url', Version: 1.1, Content: System.Net.Http.ByteArrayContent, Headers:
{
  Accept: application/json; charset=utf-8
  Content-Type: application/json; charset=utf-8
}
2024-06-19 11:23:12.937 TRACE HttpCommandExecutor: << StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Cache-Control: no-cache
  Content-Length: 14
  Content-Type: application/json; charset=utf-8
}
2024-06-19 11:23:12.937 DEBUG HttpCommandExecutor: Response: ( Success: )
2024-06-19 11:23:15.952 DEBUG HttpCommandExecutor: Executing command: [3935f440fb9c568caa4de3c93b72f51c]: quit {}
2024-06-19 11:23:15.953 TRACE HttpCommandExecutor: >> Method: DELETE, RequestUri: 'http://localhost:56867/session/3935f440fb9c568caa4de3c93b72f51c', Version: 1.1, Content: <null>, Headers:
{
}
2024-06-19 11:23:16.014 TRACE HttpCommandExecutor: << StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Cache-Control: no-cache
  Content-Length: 14
  Content-Type: application/json; charset=utf-8
}
2024-06-19 11:23:16.015 DEBUG HttpCommandExecutor: Response: ( Success: )
titusfortner commented 1 week ago

You shouldn't be passing this in:

var driver = new ChromeDriver(AppDomain.CurrentDomain.BaseDirectory, options);

Just use the options class.

github-actions[bot] commented 1 week ago

💬 Please ask questions at:

frankechen commented 1 week ago

You shouldn't be passing this in:

var driver = new ChromeDriver(AppDomain.CurrentDomain.BaseDirectory, options);

Just use the options class.

Still fail to open chrome. see the logs. We already test it (not pass driver path) and test using SeleniumManager (use dictionary value saves chrome driver path). We are curious about the delete request 'http://localhost:63657/session/', why the request hits IIS server? Will windows proxy setting cause it?

2024-06-21T02:09:48.2892615Z 2024-06-21 04:09:01.801 TRACE SeleniumManager: Driver path: C:\Users\xxx\.cache\selenium\chromedriver\win64\126.0.6478.63\chromedriver.exe
2024-06-21T02:09:48.2894847Z 2024-06-21 04:09:01.821 TRACE SeleniumManager: Browser path: C:\Program Files\Google\Chrome\Application\chrome.exe
2024-06-21T02:09:48.2896733Z 2024-06-21 04:09:22.157 DEBUG HttpCommandExecutor: Executing command: []: quit {}
2024-06-21T02:09:48.2899270Z 2024-06-21 04:09:22.184 TRACE HttpCommandExecutor: >> Method: DELETE, RequestUri: 'http://localhost:63657/session/', Version: 1.1, Content: <null>, Headers:
2024-06-21T02:09:48.2900790Z {
2024-06-21T02:09:48.2903622Z }
2024-06-21T02:09:48.2907683Z 2024-06-21 04:09:22.961 TRACE HttpCommandExecutor: << StatusCode: 405, ReasonPhrase: 'Method Not Allowed', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
2024-06-21T02:09:48.2908971Z {
2024-06-21T02:09:48.2916259Z   Server: Microsoft-IIS/10.0
2024-06-21T02:09:48.3081911Z   Date: Fri, 21 Jun 2024 02:09:22 GMT
2024-06-21T02:09:48.3082886Z   Allow: GET, HEAD, OPTIONS, TRACE
2024-06-21T02:09:48.3085810Z   Content-Type: text/html
2024-06-21T02:09:48.3086987Z   Content-Length: 1293
2024-06-21T02:09:48.3087551Z }
2024-06-21T02:09:48.3089537Z 2024-06-21 04:09:22.972 DEBUG HttpCommandExecutor: Response: ( UnhandledError: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2024-06-21T02:09:48.3090739Z <html xmlns="http://www.w3.org/1999/xhtml">
2024-06-21T02:09:48.3091328Z <head>
2024-06-21T02:09:48.3092402Z <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
2024-06-21T02:09:48.3093657Z <title>405 - HTTP verb used to access this page is not allowed.</title>
2024-06-21T02:09:48.3094366Z <style type="text/css">
2024-06-21T02:09:48.3094970Z <!--
2024-06-21T02:09:48.3097037Z body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}
2024-06-21T02:09:48.3098461Z fieldset{padding:0 15px 10px 15px;} 
2024-06-21T02:09:48.3100051Z h1{font-size:2.4em;margin:0;color:#FFF;}
2024-06-21T02:09:48.3101336Z h2{font-size:1.7em;margin:0;color:#CC0000;} 
2024-06-21T02:09:48.3102826Z h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} 
2024-06-21T02:09:48.3104774Z #header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;
2024-06-21T02:09:48.3106202Z background-color:#555555;}
2024-06-21T02:09:48.3107091Z #content{margin:0 0 0 2%;position:relative;}
2024-06-21T02:09:48.3108762Z .content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}
2024-06-21T02:09:48.3109938Z -->
2024-06-21T02:09:48.3110486Z </style>
2024-06-21T02:09:48.3110995Z </head>
2024-06-21T02:09:48.3111541Z <body>
2024-06-21T02:09:48.3112149Z <div id="header"><h1>Server Error</h1></div>
2024-06-21T02:09:48.3112883Z <div id="content">
2024-06-21T02:09:48.3113862Z  <div class="content-container"><fieldset>
2024-06-21T02:09:48.3115011Z   <h2>405 - HTTP verb used to access this page is not allowed.</h2>
2024-06-21T02:09:48.3116028Z   <h3>The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access.</h3>
2024-06-21T02:09:48.3121537Z  </fieldset></div>
2024-06-21T02:09:48.3122014Z </div>
2024-06-21T02:09:48.3122425Z </body>
2024-06-21T02:09:48.3122868Z </html>
2024-06-21T02:09:48.3123273Z )
titusfortner commented 1 week ago

What is your code? It appears that you are sending driver commands to a web server instead of to a driver.

Please see https://www.selenium.dev/documentation/webdriver/getting_started/

frankechen commented 6 days ago

What is your code? It appears that you are sending driver commands to a web server instead of to a driver.

Please see https://www.selenium.dev/documentation/webdriver/getting_started/

attach sample code below. we use the sample method from that Get Started to open web page.

using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Internal.Logging;
using System.Net.NetworkInformation;

namespace SimpleApp
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
            Log.SetLevel(LogEventLevel.Trace);
            Log.Handlers.Add(new FileLogHandler(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log.txt")));
            CheckPorts();
            try
            {
                var options = new ChromeOptions();
                options.AddArgument("--incognito");
                options.AddArgument("--window-size=800,600");
                Console.WriteLine("create chrome options");
                var driver = new ChromeDriver(AppDomain.CurrentDomain.BaseDirectory, options);
                Console.WriteLine("create chrome driver");

                CheckPorts();
                driver.Navigate().GoToUrl("https://www.bing.com");
                Thread.Sleep(3000);

                driver.Dispose();
                Console.WriteLine("dispose chrome driver");
            }
            catch (Exception ex)
            {
                Console.WriteLine("catch error");
                Console.WriteLine(ex.Message);
                CheckPorts();
            }
            Console.WriteLine("the end");
        }

        static void CheckPorts()
        {
            var props = IPGlobalProperties.GetIPGlobalProperties();
            var points = props.GetActiveTcpListeners();
            Console.WriteLine(string.Join(",", points.Select(p => p.Port).Distinct().OrderBy(p => p)).ToArray());
        }
    }
}
titusfortner commented 5 days ago

This code does not do what you think it does: new ChromeDriver(AppDomain.CurrentDomain.BaseDirectory, options)

Just use: new ChromeDriver(options)

frankechen commented 5 days ago

This code does not do what you think it does: new ChromeDriver(AppDomain.CurrentDomain.BaseDirectory, options)

Just use: new ChromeDriver(options)

I remember that you mentioned it several days ago, we already tested it.

var driver = new ChromeDriver(options);

Not work, see my previous reply https://github.com/SeleniumHQ/selenium/issues/14146#issuecomment-2181869274