0

I'm tring to start devTools with ChromeDriver or EdgeDriver; in both cases by running this code the machine start to wait infinite when run devTools.GetDevToolsSession() (tested in debug). Without getting the devTool all works. Computer win 10, Selenuim 4.9 (we tried 4.8, 4.0 too), chromedriver 114, Chorme 114

Dim driver = New ChromeDriver(MyApp.AssetsPath)
Dim devTools As IDevTools = driver
Dim session As DevToolsSession = devTools.GetDevToolsSession()

...

We would like to access to network resources when selenium navigate to url. When we tried to avoid the problem we notice that the manager.StartMonitoring() rise the same infinite wait.

Dim driver = New ChromeDriver(MyApp.AssetsPath)
SetupNetworkLoggingAsync(driver)

...

    Public Async Function SetupNetworkLoggingAsync(driver As IWebDriver) As Threading.Tasks.Task
        Dim manager As NetworkManager = New NetworkManager(driver)
        AddHandler manager.NetworkResponseReceived, AddressOf ResponseHandler
        Await manager.StartMonitoring()
    End Function

Code tested in two different computers. Have you ever encountered a similar problem?

  • Are you using Windows Forms? StartMonitoring doesn't work. See : https://stackoverflow.com/questions/71885535/c-sharp-selenium-how-to-use-proxy-with-authentication?force_isolation=true – jdweng Jun 07 '23 at 10:45
  • Thank you Jdweng, your answer put me in the right way. I founded the solution: vb.net with web form can't run async selenium functions. When we had tryed to run the same code with vb.net for console application all works fine. So we made a vb.net website that call a .bat in the server with selenium code – Dr. Clò Luca Jun 09 '23 at 12:55

2 Answers2

0

If you would like to do this please look at this page.

But please take note of the comment at the top of the page:

While Selenium 4 provides direct access to the Chrome DevTools Protocol (CDP), it is highly encouraged that you use the WebDriver Bidi APIs instead.

Source

BiDirectional API (CDP implementation)

(Unfortunatly no VB.Net / c# samples at this time...)

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.devtools.HasDevTools;
import org.openqa.selenium.devtools.NetworkInterceptor;
import org.openqa.selenium.remote.http.Contents;
import org.openqa.selenium.remote.http.Filter;
import org.openqa.selenium.remote.http.HttpResponse;
import org.openqa.selenium.remote.http.Route;

NetworkInterceptor interceptor = new NetworkInterceptor(
  driver,
  Route.matching(req -> true)
    .to(() -> req -> new HttpResponse()
      .setStatus(200)
      .addHeader("Content-Type", MediaType.HTML_UTF_8.toString())
      .setContent(utf8String("Creamy, delicious cheese!"))));

driver.get("https://example-sausages-site.com");

String source = driver.getPageSource();

assertThat(source).contains("delicious cheese!");

Source

BernardV
  • 640
  • 10
  • 28
  • Thank you for the answer. I founded the solution: vb.net with web form can't run async selenium functions. When we had tryed to run the same code with vb.net for console application all works fine. – Dr. Clò Luca Jun 09 '23 at 12:53
  • I think I found reason. See : https://stackoverflow.com/questions/70529101/there-are-no-createdevtoolssession-in-chromedriver-selenium/71671844#71671844 – jdweng Jun 09 '23 at 13:26
0

Try this way, it resolved GetDevToolsSession() waiting forever on my WinForms app

await Task.Run(() => { m_devToolsSession = (m_chromeDriver as IDevTools).GetDevToolsSession(); });

Reference: https://github.com/SeleniumHQ/selenium/issues/10008

ZIQIANG ZHAO
  • 61
  • 1
  • 1