Get Window handle (IntPtr) from Selenium webdriver's current window GUID

后端 未结 3 1675
野趣味
野趣味 2021-01-17 17:43

I\'m trying to capture a screenshot of whole browser screen (e.g. with any toolbars, panels and so on) not only an entire page, so I\'m got this code:

using          


        
3条回答
  •  醉酒成梦
    2021-01-17 18:17

    You could get the window handle using Process.GetProcesses:

    using (FirefoxDriver driver = new FirefoxDriver())
    {
        driver.Navigate().GoToUrl(url);
    
        string title = String.Format("{0} - Mozilla Firefox", driver.Title);
        var process = Process.GetProcesses()
            .FirstOrDefault(x => x.MainWindowTitle == title);
    
        if (process != null)
        {
            var screenCapture = new ScreenCapture();
            var image = screenCapture.CaptureWindow(process.MainWindowHandle);
            // ...
        }
    }
    

    This of course assumes that you have a single browser instance with that specific title.

提交回复
热议问题