0

我是硒的新手。实际上我正在做一些cookie验证项目,这需要我在多个浏览器(Firefox,即chrome,safari)中单击某些同意链接之前和之后手动检查存在的cookie。

之前在第 1 阶段项目中,我运行了一个 qtp 脚本来将 firefox 视为窗口对象并捕获屏幕截图,但如果分辨率发生变化或任何细微的外观变化,这将非常麻烦。此外,它也很难管理,它只能在 Firefox 上运行,我需要再次为 chrome 和 safari 编写相同的脚本。除此之外,由于 QTP 是许可产品,目前我们使用的是单机许可,因此我无法在多台机器上运行它以加快执行速度。

所以我想搬到 Selenium。目前我的要求是:

1. open the page - take the screenshot once page loaded.
2. check the cookies using firebug or any other way  - take the screenshot
3. click the link to close the consent - take screenshot once consent closed.
4. refresh the page and again check the cookies using firebug - take screenshot

所以我对 selenium 做了一些研究,发现我可以使用 verifyCookie 验证 cookie,但我仍然需要 cookie 的萤火虫窗口截图。所以我被困在这里。

请帮我在这里..

我在 Firefox 上找到了一些可能的方法,但现在我期待在 Chrome 上找到类似的方法,如果可能的话。谢谢

4

3 回答 3

1

Selenium 无法以您希望的方式与 firefox 扩展或浏览器交互。

您可以通过以下方式收集页面上的 cookie 列表:

driver.manage().getCookies()

这将为您提供 Selenium 可见的所有 cookie 的列表。请注意,这与 JavaScript 控制台中可见的 cookie 相同(并非所有 cookie 都通过 JavaScript 可见,例如使用 HTTPOnly 属性设置的 cookie)使用:

document.cookie

我建议您使用 getCookies() 以编程方式验证 cookie。

于 2013-03-18T09:14:44.560 回答
0

在 selenium IDE 中,如果您想截取页面使用captureEntirePageScreenshot命令的屏幕截图

   captureEntirePageScreenshot | D:\\test.png | 

     D:\\test.png - path of file where you want to save the file
于 2013-03-21T11:50:47.897 回答
0

得到了一些解决方案

public class Selenium1st {

    /**
     * @param args
     */
    public static void main(String[] args) throws IOException, AWTException{
        // TODO Auto-generated method stub      
        System.setProperty("webdriver.firefox.bin","C:\\Program Files (x86)\\Mozilla Firefox\\Firefox.exe");
        FirefoxProfile firefoxProfile = new FirefoxProfile();

        String domain = "extensions.firebug.";
        firefoxProfile.setPreference("app.update.enabled", false);
        firefoxProfile.addExtension(new File("E:\\softs\\selenium-2.29.0\\firebug\\firebug-1.11.2-fx.xpi"));
        firefoxProfile.setPreference(domain + "currentVersion", "1.11.2");
        firefoxProfile.setPreference("extensions.firebug.cookies.enableSites", true);
        firefoxProfile.setPreference("extensions.firebug.allPagesActivation", "on");

        firefoxProfile.setPreference(domain + "framePosition", "bottom");
        firefoxProfile.setPreference(domain + "defaultPanelName", "cookies");

        WebDriver driver = new FirefoxDriver(firefoxProfile);
        driver.get("http://www.google.com/webhp?complete=1&hl=en");
        WebElement query = driver.findElement(By.name("q"));
        query.sendKeys("Cheese");
        query.sendKeys("\n");
        Robot robot = new Robot();
        BufferedImage img = robot.createScreenCapture(new Rectangle(new Dimension(1024, 768)));

        File path = new File("E:\\abc");//Path to your file
        if(path.getName().indexOf(".jpg") == -1){
            path = new File(path.getPath() + ".jpg");
        }       
        ImageIO.write(img, "jpg", path);                
    }

}

可能有用。

于 2013-04-12T08:12:26.870 回答