线程“主” org.openqa.selenium.WebDriverException中的异常:无法设置cookie(会话信息:chrome = 70.0.3538.102)

时间:2018-11-19 09:25:15

标签: java selenium-chromedriver

  • 环境:Windows 7 + chrome70.0.3538.102(64位)+ selenium-java(3.141.59)+ selenium-chrome-driver(3.141.59)+ java

            //obtain cookies
        WebClient webClient0 = new WebClient();
        webClient0.setJavaScriptEnabled(false);
        webClient0.setThrowExceptionOnScriptError(false);
        webClient0.setCssEnabled(false);
        webClient0.getCookieManager().setCookiesEnabled(true);
        CookieManager cookieManager = webClient0.getCookieManager();
        HtmlPage login1Page;
        try {
            login1Page = webClient0.getPage("http://10.91.42.124:9999/login1.php");
            HtmlInput username = (HtmlInput) login1Page.getElementById("username");
            HtmlInput passwd = (HtmlInput) login1Page.getElementById("password");
            username.type("admin");
            passwd.type("admin123");
            HtmlButton loginButton = (HtmlButton)login1Page.getElementById("loginb");
            HtmlPage TChtmlPage = loginButton.click();
            cookies = cookieManager.getCookies();
            System.out.println(cookies);
        } catch (FailingHttpStatusCodeException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }           
    try {
            chromeDriverPath = System.getProperty("user.dir")+"\\src\\main\\resources\\chromedriver.exe";
            //set up the path of chrome drive
            System.setProperty("webdriver.chrome.driver", chromeDriverPath);
            //open chrome client
            chromeDriver = new ChromeDriver();
            chromeDriver.get("http://10.91.42.134:8360/TC.php");
            for(org.apache.commons.httpclient.Cookie cookie : cookies) {
                chromeCookie = new Cookie(cookie.getName(), cookie.getValue(), 
                        cookie.getDomain(), cookie.getExpiryDate());
                chromeDriver.manage().addCookie(chromeCookie);
            }
    
  • 然后生成此错误
      

    线程“主” org.openqa.selenium.WebDriverException中的异常:无法设置cookie   (会议信息:chrome = 70.0.3538.102)   (驱动程序信息:chromedriver = 2.43.600210(68dcf5eebde37173d4027fa8635e332711aa874a),平台= Windows NT 6.1.7601 SP1 x86_64)(警告:服务器未提供任何堆栈跟踪信息)   命令持续时间或超时:0毫秒

我不知道这是什么意思吗?

0 个答案:

没有答案