selenium icon indicating copy to clipboard operation
selenium copied to clipboard

[🐛 Bug]: GetDevToolsSession in WPF hangs forever

Open topfunet opened this issue 3 years ago • 6 comments

What happened?

GetDevToolsSession in WPF Application hangs forever, but same code in Console Application work fine.

How can we reproduce the issue?

MainWindow.xaml:
<Button Content="Just Click" Click="Button_Click"></Button>

MainWindow.xaml.cs:
private void Button_Click(object sender, RoutedEventArgs e)
{
    IWebDriver driver = new ChromeDriver();
    IDevTools devTools = driver as IDevTools;
    DevToolsSession session = devTools.GetDevToolsSession(); //this line never return
    driver.Navigate().GoToUrl("https://bing.com");
    driver.Quit();
}

Relevant log output

no relevant log output and vs2019 hasn't error log

Operating System

windows 10

Selenium version

.net c# 4.0.1

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

chrome 95.0.4638.69

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

ChromeDriver 95.0.4638.5401

Are you using Selenium Grid?

no

topfunet avatar Nov 03 '21 11:11 topfunet

@topfunet, 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.

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

Thank you!

github-actions[bot] avatar Nov 03 '21 11:11 github-actions[bot]

I have the same issue, any news on this?

jensakejohansson avatar Feb 03 '22 15:02 jensakejohansson

I have the same issue, any news on this?

I have same problem - goes OK only in console app, on Winform - hangs up

ihor2005 avatar Feb 17 '22 18:02 ihor2005

I'm also using Winforms and ran into this issue. As a workaround for now, creating a new thread and working with Selenium from there seems OK.

michaelhazm1 avatar Mar 23 '22 03:03 michaelhazm1

I have the same issue, it keeps loading forever.

Does someone know how to solve it?

            ChromeOptions options = new ChromeOptions();
            options.AddArguments("--start-maximized");
            options.AddArguments("--test-type");

            IWebDriver driver = new ChromeDriver(@"C:\Drivers\", options);
            var devTools = (IDevTools)driver;

            IDevToolsSession session = devTools.GetDevToolsSession();

alttabs avatar May 06 '22 13:05 alttabs

I was also facing the same issue in my project. I don't think that app type is the problem there, the issue is the context within which you are trying to get the session with DevToolsSession session = devTools.GetDevToolsSession();. Let me explain it on my example. Background I have a custom web testing framework which consist of 2 projects - Web tests project [UITests] + Selenium project [Core]. UITests is the place where I store all the tests written with Specflow library, page objects, steps implementation and all stuff related to the System Under Test [SUT]. Core is the main framework shareable between different SUT projects, it contains common logic such as WebDriver configuration and implementation, additional helper methods etc, not related to any particular SUT.

Problem As by following good coding practices, I wanted to put session initialization inside my Core project, so then it can be reusable across other projects. Because of that, I've initially placed the GetDevToolsSession() method call in main class responsible for handling WebDriver. Unfortunately it's a part of the Core project, so I was getting the same issue as described by OP, the code was just freezing without any error.

Solution For me, the solution to that problem was just simply placing GetDevToolsSession() call inside the project I originally use for running the tests, which was UITests project. I assume if all the above examples are related to multi-project solutions, then probably you're trying to call GetDevToolsSession() inside non-executable namespace, so maybe some external library project, which for selenium is a separate context for some reason. Guess this is a bug as I can easily create new driver instance, regardless the namespace or project I'm in.

mniezgoda1 avatar May 31 '22 13:05 mniezgoda1

do this :

DevToolsSession session; private void Button_Click(object sender, RoutedEventArgs e) { IWebDriver driver = new ChromeDriver(); IDevTools devTools = driver as IDevTools; Task.Run(() => { session = devTools.GetDevToolsSession(); }); driver.Navigate().GoToUrl("https://bing.com"); driver.Quit(); }

matinfathi19 avatar Sep 25 '22 08:09 matinfathi19

do this :

DevToolsSession session; private void Button_Click(object sender, RoutedEventArgs e) { IWebDriver driver = new ChromeDriver(); IDevTools devTools = driver as IDevTools; Task.Run(() => { session = devTools.GetDevToolsSession(); }); driver.Navigate().GoToUrl("https://bing.com"); driver.Quit(); }

Running on a thread does not solve the problem!

session == null

maestroant avatar Mar 16 '23 17:03 maestroant

Firefox also.

hheexx avatar May 28 '23 00:05 hheexx

do this : DevToolsSession session; private void Button_Click(object sender, RoutedEventArgs e) { IWebDriver driver = new ChromeDriver(); IDevTools devTools = driver as IDevTools; Task.Run(() => { session = devTools.GetDevToolsSession(); }); driver.Navigate().GoToUrl("https://bing.com"); driver.Quit(); }

Running on a thread does not solve the problem!

session == null

try to .Wait() on Task.Run

hheexx avatar May 28 '23 01:05 hheexx

Should be fixed in 4.12, please verify.

nvborisenko avatar Sep 01 '23 15:09 nvborisenko

Feel free to reopen this issue if it is still an issue.

nvborisenko avatar Oct 03 '23 18:10 nvborisenko

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Dec 04 '23 00:12 github-actions[bot]