【问题标题】:Capture Screenshot of entire page with Selenium in IE9在 IE9 中使用 Selenium 捕获整个页面的屏幕截图
【发布时间】:2011-10-25 17:28:12
【问题描述】:

我正在尝试让CaptureEntirePageScreenshot 为 IE9 工作。我已经阅读了很多文档和 wiki 来完成这项工作,但到目前为止对我没有任何帮助。

所以我想我会直接使用 snapsie。所以我下载了 dll 并使用这些instructions 注册了它。然后我就直接用了:

selenium.GetEval(js_code + "this.browserbot.getUserWindow().Snapsie.saveSnapshot('C:\\pic\\test.png');");

但是,我得到了错误:

自动化服务器无法创建对象

有什么想法吗?

对于让 snapsie.js 正常工作的任何一般帮助,我将不胜感激。我在装有 IE9 和 FF4 的 Windows 7 机器上使用最新的 selenium 服务器 (2.9.0)。我正在使用 C#。

【问题讨论】:

    标签: c# selenium selenium-webdriver


    【解决方案1】:

    我不确定您为什么使用 Snapsie,但从 Internetexplorer 获取屏幕截图的最简单方法是使用 InternetExplorerDriver 本身:

    IWebDriver driver;
    driver = new InternetExplorerDriver();
    // change this line if you want to use an different Browser / WebDriver Implementation
    //driver = new FirefoxDriver();
    driver.Navigate().GoToUrl("http://www.google.com/");
    IWebElement query = driver.FindElement(By.Name("q"));
    query.SendKeys("Cheese");
    // TODO: wait
    ((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(@"screenIE.png", ImageFormat.Png);
    

    【讨论】:

    • 这看起来不适用于 selenium。我不能只打开另一个浏览器到另一个页面。
    • 我确信它适用于 selenium (Selenium 2 / WebDriver),我刚刚尝试过。将我的代码放在一个简单的 C# 控制台应用程序中,引用 Selenium .Net dll 并启动它。
    • 我不只是针对 IE。我正在使用 Selenium 打开几个浏览器。所以我不能将上述内容与 Selenium 一起使用,因为 Selenium 不会驱动测试用例,它将是 InternetExplorerDriver。
    • 好的,比稍微改变一下代码。使用接口,并使用您想要的任何 Selenum(浏览器)实现。 --> 我将答案的代码更改为更通用的用法。 (除此之外,我想知道如果您想使用任何浏览器,为什么您将问题称为“在 IE9 中捕获屏幕截图”!?)
    • 非常感谢!迁移到 Web 驱动程序会很困难,但它可以做我需要它做的事情。
    猜你喜欢
    • 2023-01-23
    • 2019-01-31
    • 2017-12-25
    • 2011-10-13
    • 2012-11-29
    • 2012-10-26
    • 1970-01-01
    • 2015-04-03
    相关资源
    最近更新 更多