• [Selenium] 应对使用 Internet Explorer Driver 多个实例时的 cookie 共享问题


    在使用 IEDriverServer 可执行文件时,从理论上来说是可通过它来创建并使用多个同时存在的 Internet Explorer Driver 实例的。但在实际使用过程中,总是会碰到与 cookie 相关的问题、窗口焦点的问题、浏览器多实例等可能会面临的问题。如果真想希望使用 Internet Explorer Driver 的多个实例并且尽可能的避免前述可能遇到的问题,建议考虑 RemoteWebDriver 的方式,并通过多台虚拟机来隔离干扰

      有一种解决方案来应对使用 Internet Explorer Driver 多个实例时的 cookie 共享问题,即在Internet Explorer 启动时先清理回话中的脏数据。可通过将 IE_ENSURE_CLEAN_SESION 参数传递给 Internet Explorer Driver 并在此模式下启动 Internet Explorer Driver 来达到目的,代码如下

    pachage com.learningselenium.simplewebdriver;

    import org.openqa.selenium.*;

    import org.openqa.selenium.ie.InternetExplorerDriver;

    import org.openqa.selenium.remote.DesiredCapabilities;

    public class testInternetExplorerDriver{

      public static void main(String[] args){

        System.setProperty("webdriver.ie.driver", "D:DriverIEDriverServer_ Win32_ 2.37.0_latestIEDriverServer.exe");

        //设置DesiredCapabilities 的属性包含IE_ENSURE_CLEAN_SESSION 以确保在浏览器实例启动之前清理会话的脏数据

        DesiredCapabilities capab = DesiredCapabilities.internetExplorer();

        capab.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true); 

        Webdriver driver = new InternetExplorerDriver(capab);

        driver.get("http://www.baidu.com");

      }

    }

  • 相关阅读:
    xdvipdfmx:fatal: Unable to open "xxx.pdf". Output file removed. fwrite: Broken pipe xelatex.exe
    安装Visual Studio 时窗口闪过就退出
    一些概念的收集
    如何让字符串中奇怪的空格现出原形
    mysql替换特殊字符
    asscii码对应表
    Linux下的tar压缩解压缩命令详解
    centos 6.8 /etc/sysconfig/下没有iptables的问题
    mysqldumpslow简单用法
    linux查询占用空间较大的文件
  • 原文地址:https://www.cnblogs.com/feifeidxl/p/4549192.html
Copyright © 2020-2023  润新知