selenium获取cookies

<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.0.0</version>
</dependency>

import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
/**
 * @author liwen406
 * @Title: seleniumDome
 * @Description:
 * @date 2019/1/27 / 18:38
 */
public class seleniumDome {
    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver","C:\\Users\\liwen406\\Downloads\\chromedriver_win32\\chromedriver.exe");//chromedriver服务地址
        WebDriver driver =new ChromeDriver(); //新建一个WebDriver 的对象,但是new 的是FirefoxDriver的驱动
        driver.get("http://www.baidu.com");//打开指定的网站

        driver.findElement(By.id("kw")).sendKeys(new  String[] {"hello"});//找到kw元素的id,然后输入hello
        driver.findElement(By.id("su")).click(); //点击按扭
        Set<Cookie> cookies = driver.manage().getCookies();
        System.out.println(cookies);

        try {
            /**
             * WebDriver自带了一个智能等待的方法。
             dr.manage().timeouts().implicitlyWait(arg0, arg1);
             Arg0:等待的时间长度,int 类型 ;
             Arg1:等待时间的单位 TimeUnit.SECONDS 一般用秒作为单位。
             */
            driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
        } catch (Exception e) {
            e.printStackTrace();
        }
        /**
         * dr.quit()和dr.close()都可以退出浏览器,简单的说一下两者的区别:第一个close,
         * 如果打开了多个页面是关不干净的,它只关闭当前的一个页面。第二个quit,
         * 是退出了所有Webdriver所有的窗口,退的非常干净,所以推荐使用quit最为一个case退出的方法。
         */
        try {
            Thread.sleep(6000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        driver.quit();//退出浏览器
    }
}

"C:\Program Files (x86)\Java\jdk1.8.0_181\bin\java.exe" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:52675,suspend=y,server=n -javaagent:C:\Users\liwen406.IntelliJIdea2018.2\system\captureAgent\debugger-agent.jar=file:/C:/Users/liwen406/AppData/Local/Temp/capture.props -Dfile.encoding=UTF-8 -classpath "C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\charsets.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\deploy.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\ext\access-bridge-32.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\ext\cldrdata.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\ext\dnsns.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\ext\jaccess.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\ext\jfxrt.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\ext\localedata.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\ext\nashorn.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\ext\sunec.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\ext\sunjce_provider.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\ext\sunmscapi.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\ext\sunpkcs11.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\ext\zipfs.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\javaws.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\jce.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\jfr.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\jfxswt.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\jsse.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\management-agent.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\plugin.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\resources.jar;C:\Program Files (x86)\Java\jdk1.8.0_181\jre\lib\rt.jar;D:\javaspaces\githup\mysqldome\target\test-classes;D:\javaspaces\githup\mysqldome\target\classes;D:\Program Files (x86)\repository\org\springframework\boot\spring-boot-starter-jdbc\2.1.1.RELEASE\spring-boot-starter-jdbc-2.1.1.RELEASE.jar;D:\Program Files (x86)\repository\org\springframework\boot\spring-boot-starter\2.1.1.RELEASE\spring-boot-starter-2.1.1.RELEASE.jar;D:\Program Files (x86)\repository\org\springframework\boot\spring-boot-starter-logging\2.1.1.RELEASE\spring-boot-starter-logging-2.1.1.RELEASE.jar;D:\Program Files (x86)\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\Program Files (x86)\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\Program Files (x86)\repository\org\apache\logging\log4j\log4j-to-slf4j\2.11.1\log4j-to-slf4j-2.11.1.jar;D:\Program Files (x86)\repository\org\apache\logging\log4j\log4j-api\2.11.1\log4j-api-2.11.1.jar;D:\Program Files (x86)\repository\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;D:\Program Files (x86)\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;D:\Program Files (x86)\repository\org\yaml\snakeyaml\1.23\snakeyaml-1.23.jar;D:\Program Files (x86)\repository\com\zaxxer\HikariCP\3.2.0\HikariCP-3.2.0.jar;D:\Program Files (x86)\repository\org\springframework\boot\spring-boot-starter-web\2.1.1.RELEASE\spring-boot-starter-web-2.1.1.RELEASE.jar;D:\Program Files (x86)\repository\org\springframework\boot\spring-boot-starter-json\2.1.1.RELEASE\spring-boot-starter-json-2.1.1.RELEASE.jar;D:\Program Files (x86)\repository\com\fasterxml\jackson\core\jackson-databind\2.9.7\jackson-databind-2.9.7.jar;D:\Program Files (x86)\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;D:\Program Files (x86)\repository\com\fasterxml\jackson\core\jackson-core\2.9.7\jackson-core-2.9.7.jar;D:\Program Files (x86)\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.7\jackson-datatype-jdk8-2.9.7.jar;D:\Program Files (x86)\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.7\jackson-datatype-jsr310-2.9.7.jar;D:\Program Files (x86)\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.7\jackson-module-parameter-names-2.9.7.jar;D:\Program Files (x86)\repository\org\springframework\boot\spring-boot-starter-tomcat\2.1.1.RELEASE\spring-boot-starter-tomcat-2.1.1.RELEASE.jar;D:\Program Files (x86)\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.13\tomcat-embed-core-9.0.13.jar;D:\Program Files (x86)\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.13\tomcat-embed-el-9.0.13.jar;D:\Program Files (x86)\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.13\tomcat-embed-websocket-9.0.13.jar;D:\Program Files (x86)\repository\org\hibernate\validator\hibernate-validator\6.0.13.Final\hibernate-validator-6.0.13.Final.jar;D:\Program Files (x86)\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;D:\Program Files (x86)\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;D:\Program Files (x86)\repository\com\fasterxml\classmate\1.4.0\classmate-1.4.0.jar;D:\Program Files (x86)\repository\org\springframework\spring-web\5.1.3.RELEASE\spring-web-5.1.3.RELEASE.jar;D:\Program Files (x86)\repository\org\springframework\spring-webmvc\5.1.3.RELEASE\spring-webmvc-5.1.3.RELEASE.jar;D:\Program Files (x86)\repository\org\springframework\spring-aop\5.1.3.RELEASE\spring-aop-5.1.3.RELEASE.jar;D:\Program Files (x86)\repository\org\springframework\spring-expression\5.1.3.RELEASE\spring-expression-5.1.3.RELEASE.jar;D:\Program Files (x86)\repository\org\springframework\spring-jdbc\5.1.3.RELEASE\spring-jdbc-5.1.3.RELEASE.jar;D:\Program Files (x86)\repository\org\springframework\spring-beans\5.1.3.RELEASE\spring-beans-5.1.3.RELEASE.jar;D:\Program Files (x86)\repository\org\springframework\spring-core\5.1.3.RELEASE\spring-core-5.1.3.RELEASE.jar;D:\Program Files (x86)\repository\org\springframework\spring-jcl\5.1.3.RELEASE\spring-jcl-5.1.3.RELEASE.jar;D:\Program Files (x86)\repository\org\springframework\spring-tx\5.1.3.RELEASE\spring-tx-5.1.3.RELEASE.jar;D:\Program Files (x86)\repository\mysql\mysql-connector-java\8.0.13\mysql-connector-java-8.0.13.jar;D:\Program Files (x86)\repository\org\springframework\boot\spring-boot-starter-thymeleaf\2.1.1.RELEASE\spring-boot-starter-thymeleaf-2.1.1.RELEASE.jar;D:\Program Files (x86)\repository\org\thymeleaf\thymeleaf-spring5\3.0.11.RELEASE\thymeleaf-spring5-3.0.11.RELEASE.jar;D:\Program Files (x86)\repository\org\thymeleaf\thymeleaf\3.0.11.RELEASE\thymeleaf-3.0.11.RELEASE.jar;D:\Program Files (x86)\repository\org\attoparser\attoparser\2.0.5.RELEASE\attoparser-2.0.5.RELEASE.jar;D:\Program Files (x86)\repository\org\unbescape\unbescape\1.1.6.RELEASE\unbescape-1.1.6.RELEASE.jar;D:\Program Files (x86)\repository\org\thymeleaf\extras\thymeleaf-extras-java8time\3.0.2.RELEASE\thymeleaf-extras-java8time-3.0.2.RELEASE.jar;D:\Program Files (x86)\repository\org\springframework\boot\spring-boot-starter-test\2.1.1.RELEASE\spring-boot-starter-test-2.1.1.RELEASE.jar;D:\Program Files (x86)\repository\org\springframework\boot\spring-boot-test\2.1.1.RELEASE\spring-boot-test-2.1.1.RELEASE.jar;D:\Program Files (x86)\repository\org\springframework\boot\spring-boot-test-autoconfigure\2.1.1.RELEASE\spring-boot-test-autoconfigure-2.1.1.RELEASE.jar;D:\Program Files (x86)\repository\com\jayway\jsonpath\json-path\2.4.0\json-path-2.4.0.jar;D:\Program Files (x86)\repository\net\minidev\json-smart\2.3\json-smart-2.3.jar;D:\Program Files (x86)\repository\net\minidev\accessors-smart\1.2\accessors-smart-1.2.jar;D:\Program Files (x86)\repository\junit\junit\4.12\junit-4.12.jar;D:\Program Files (x86)\repository\org\assertj\assertj-core\3.11.1\assertj-core-3.11.1.jar;D:\Program Files (x86)\repository\org\mockito\mockito-core\2.23.4\mockito-core-2.23.4.jar;D:\Program Files (x86)\repository\net\bytebuddy\byte-buddy\1.9.5\byte-buddy-1.9.5.jar;D:\Program Files (x86)\repository\net\bytebuddy\byte-buddy-agent\1.9.5\byte-buddy-agent-1.9.5.jar;D:\Program Files (x86)\repository\org\objenesis\objenesis\2.6\objenesis-2.6.jar;D:\Program Files (x86)\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;D:\Program Files (x86)\repository\org\hamcrest\hamcrest-library\1.3\hamcrest-library-1.3.jar;D:\Program Files (x86)\repository\org\skyscreamer\jsonassert\1.5.0\jsonassert-1.5.0.jar;D:\Program Files (x86)\repository\com\vaadin\external\google\android-json\0.0.20131108.vaadin1\android-json-0.0.20131108.vaadin1.jar;D:\Program Files (x86)\repository\org\springframework\spring-test\5.1.3.RELEASE\spring-test-5.1.3.RELEASE.jar;D:\Program Files (x86)\repository\org\xmlunit\xmlunit-core\2.6.2\xmlunit-core-2.6.2.jar;D:\Program Files (x86)\repository\com\alibaba\druid\1.1.9\druid-1.1.9.jar;D:\Program Files (x86)\repository\log4j\log4j\1.2.17\log4j-1.2.17.jar;D:\Program Files (x86)\repository\org\webjars\bootstrap\4.2.1\bootstrap-4.2.1.jar;D:\Program Files (x86)\repository\org\webjars\popper.js\1.14.3\popper.js-1.14.3.jar;D:\Program Files (x86)\repository\org\webjars\jquery\3.3.1\jquery-3.3.1.jar;D:\Program Files (x86)\repository\org\springframework\boot\spring-boot-devtools\2.1.1.RELEASE\spring-boot-devtools-2.1.1.RELEASE.jar;D:\Program Files (x86)\repository\org\springframework\boot\spring-boot\2.1.1.RELEASE\spring-boot-2.1.1.RELEASE.jar;D:\Program Files (x86)\repository\org\springframework\boot\spring-boot-autoconfigure\2.1.1.RELEASE\spring-boot-autoconfigure-2.1.1.RELEASE.jar;D:\Program Files (x86)\repository\cn\hutool\hutool-all\4.4.0\hutool-all-4.4.0.jar;D:\Program Files (x86)\repository\org\apache\httpcomponents\httpclient\4.5.6\httpclient-4.5.6.jar;D:\Program Files (x86)\repository\org\apache\httpcomponents\httpcore\4.4.10\httpcore-4.4.10.jar;D:\Program Files (x86)\repository\commons-codec\commons-codec\1.11\commons-codec-1.11.jar;D:\Program Files (x86)\repository\dom4j\dom4j\1.6.1\dom4j-1.6.1.jar;D:\Program Files (x86)\repository\xml-apis\xml-apis\1.4.01\xml-apis-1.4.01.jar;D:\Program Files (x86)\repository\com\alibaba\fastjson\1.2.49\fastjson-1.2.49.jar;D:\Program Files (x86)\repository\com\google\code\gson\gson\2.8.5\gson-2.8.5.jar;D:\Program Files (x86)\repository\org\projectlombok\lombok\1.18.4\lombok-1.18.4.jar;D:\Program Files (x86)\repository\io\appium\java-client\7.0.0\java-client-7.0.0.jar;D:\Program Files (x86)\repository\org\seleniumhq\selenium\selenium-java\3.14.0\selenium-java-3.14.0.jar;D:\Program Files (x86)\repository\org\seleniumhq\selenium\selenium-chrome-driver\3.14.0\selenium-chrome-driver-3.14.0.jar;D:\Program Files (x86)\repository\org\seleniumhq\selenium\selenium-edge-driver\3.14.0\selenium-edge-driver-3.14.0.jar;D:\Program Files (x86)\repository\org\seleniumhq\selenium\selenium-firefox-driver\3.14.0\selenium-firefox-driver-3.14.0.jar;D:\Program Files (x86)\repository\org\seleniumhq\selenium\selenium-ie-driver\3.14.0\selenium-ie-driver-3.14.0.jar;D:\Program Files (x86)\repository\org\seleniumhq\selenium\selenium-opera-driver\3.14.0\selenium-opera-driver-3.14.0.jar;D:\Program Files (x86)\repository\org\seleniumhq\selenium\selenium-remote-driver\3.14.0\selenium-remote-driver-3.14.0.jar;D:\Program Files (x86)\repository\org\seleniumhq\selenium\selenium-safari-driver\3.14.0\selenium-safari-driver-3.14.0.jar;D:\Program Files (x86)\repository\org\apache\commons\commons-exec\1.3\commons-exec-1.3.jar;D:\Program Files (x86)\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;D:\Program Files (x86)\repository\com\google\guava\guava\25.0-jre\guava-25.0-jre.jar;D:\Program Files (x86)\repository\com\google\code\findbugs\jsr305\1.3.9\jsr305-1.3.9.jar;D:\Program Files (x86)\repository\org\checkerframework\checker-compat-qual\2.0.0\checker-compat-qual-2.0.0.jar;D:\Program Files (x86)\repository\com\google\errorprone\error_prone_annotations\2.1.3\error_prone_annotations-2.1.3.jar;D:\Program Files (x86)\repository\com\google\j2objc\j2objc-annotations\1.1\j2objc-annotations-1.1.jar;D:\Program Files (x86)\repository\org\codehaus\mojo\animal-sniffer-annotations\1.14\animal-sniffer-annotations-1.14.jar;D:\Program Files (x86)\repository\com\squareup\okhttp3\okhttp\3.10.0\okhttp-3.10.0.jar;D:\Program Files (x86)\repository\com\squareup\okio\okio\1.14.1\okio-1.14.1.jar;D:\Program Files (x86)\repository\org\seleniumhq\selenium\selenium-support\3.14.0\selenium-support-3.14.0.jar;D:\Program Files (x86)\repository\org\seleniumhq\selenium\selenium-api\3.14.0\selenium-api-3.14.0.jar;D:\Program Files (x86)\repository\cglib\cglib\3.2.8\cglib-3.2.8.jar;D:\Program Files (x86)\repository\org\ow2\asm\asm\6.2.1\asm-6.2.1.jar;D:\Program Files (x86)\repository\org\apache\ant\ant\1.10.3\ant-1.10.3.jar;D:\Program Files (x86)\repository\org\apache\ant\ant-launcher\1.10.3\ant-launcher-1.10.3.jar;D:\Program Files (x86)\repository\commons-validator\commons-validator\1.6\commons-validator-1.6.jar;D:\Program Files (x86)\repository\commons-beanutils\commons-beanutils\1.9.2\commons-beanutils-1.9.2.jar;D:\Program Files (x86)\repository\commons-digester\commons-digester\1.8.1\commons-digester-1.8.1.jar;D:\Program Files (x86)\repository\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;D:\Program Files (x86)\repository\org\apache\commons\commons-lang3\3.8.1\commons-lang3-3.8.1.jar;D:\Program Files (x86)\repository\commons-io\commons-io\2.6\commons-io-2.6.jar;D:\Program Files (x86)\repository\org\springframework\spring-context\5.1.3.RELEASE\spring-context-5.1.3.RELEASE.jar;D:\Program Files (x86)\repository\org\aspectj\aspectjweaver\1.9.2\aspectjweaver-1.9.2.jar;D:\Program Files (x86)\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;D:\Program Files (x86)\repository\org\testng\testng\7.0.0-beta1\testng-7.0.0-beta1.jar;D:\Program Files (x86)\repository\com\beust\jcommander\1.72\jcommander-1.72.jar;D:\Program Files\JetBrains\IntelliJ IDEA 2018.2.6\lib\idea_rt.jar" com.example.jdbc.dao.seleniumDome
Connected to the target VM, address: ‘127.0.0.1:52675‘, transport: ‘socket‘
Starting ChromeDriver 2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387) on port 28758
Only local connections are allowed.
一月 27, 2019 6:46:53 下午 org.openqa.selenium.remote.ProtocolHandshake createSession
信息: Detected dialect: OSS
[WWW_ST=1548586014547; expires=星期日, 27 一月 2019 06:47:04 CST; path=/; domain=www.baidu.com, BD_CK_SAM=1; path=/; domain=www.baidu.com, delPer=0; path=/; domain=.baidu.com, BIDUPSID=A5A5946A0A394D7BE7143290C85AC862; expires=星期五, 14 二月 2087 10:01:00 CST; path=/; domain=.baidu.com, BDSVRTM=30; path=/; domain=www.baidu.com, PSTM=1548586028; expires=星期五, 14 二月 2087 10:01:00 CST; path=/; domain=.baidu.com, PSINO=2; path=/; domain=.baidu.com, H_PS_PSSID=1420_21126_28329_26350_28413; path=/; domain=.baidu.com, BD_UPN=12314753; expires=星期三, 06 二月 2019 06:46:53 CST; path=/; domain=www.baidu.com, BAIDUID=A5A5946A0A394D7BE7143290C85AC862:FG=1; expires=星期五, 14 二月 2087 10:01:00 CST; path=/; domain=.baidu.com, BD_HOME=0; path=/; domain=www.baidu.com]
Disconnected from the target VM, address: ‘127.0.0.1:52675‘, transport: ‘socket‘

Process finished with exit code 0

原文地址:http://blog.51cto.com/357712148/2347071

时间: 2024-11-08 00:04:11

selenium获取cookies的相关文章

用selenium获取cookies

前言:由于登录反爬措施的越来越麻烦,甚至出现了12306这种看图识物的无敌验证码,我只能说,我选择死亡.这就衍生出了使用selenium来获取获取cookies. 实例:获取qq空间cookies,亲测成功2018-3-7   from selenium import webdriver import requests import json import time 1 def get_cookies(): 2 browser = webdriver.Chrome(executable_path

javascript 获取cookies

javascript 获取cookies  function getCookie(name)//取cookies函数            {         var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));         if (arr != null) return unescape(arr[2]); return null; } var xx = ge

selenium 获取table数据

public class Table { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub WebDriver driver = ExplorerBase.IESetting(); String url = "http://zs.njust.edu.cn/newzs/news/zhxw/20140710151805.htm"; driver.m

selenium获取多窗口句柄并一一切换至原窗口句柄(三个窗口)

网上有很多是selenium基于python来获取两个窗口句柄与切换,本文实现用python+selenium获取多窗口句柄并一一切换至原窗口句柄(三个窗口),且在每个窗口下进行一个搜索或翻译,然后截图. 代码如下: 1 # coding=utf-8 2 from selenium import webdriver 3 import time 4 5 driver = webdriver.Chrome() 6 driver.maximize_window() # 窗口最大化 7 8 driver

PHP CURL获取cookies模拟登录的方法

要提取google搜索的部分数据,发现google对于软件抓取它的数据屏蔽的厉害,以前伪造下 USER-AGENT 就可以抓数据,但是现在却不行了.利用抓包数据发现,Google 判断了 cookies,当你没有cookies的时候,直接返回 302 跳转,而且是连续几十个302跳转,根本抓不了数据. 因此,在发送搜索命令时,需要先提取 cookies 并保存,然后利用保存下来的这个cookies再次发送搜索命令即可正常抓数据了.这其实和论坛的模拟登录一个道理,先POST登录,获取cookies

JSCover+WebDriver/Selenium获取JS代码覆盖率

我们在看JSCover(http://tntim96.github.io/JSCover/manual/manual.xml)介绍及使用说明的时候,往往被图形界面所吸引.这种方式比较适合手工操作,点击和输入即可. 但是这种往往界面和真实界面相差比较大,因为真正的网页在JSCover内部的浏览加载框中.这使得原有的Selenium代码可能存在诸多问题.那么如何能够尽量少地改变原有的selenium代码而又获取到js的code coverage呢?这可以采用文件模式(File Mode). 1. I

Javascript ajax获取cookies

在单页面应用中,有时候需要在服务器中获取cookies, token等等,但是ajax并不获取cookies 和token 这是因为ajax的设计就不是这样用的 不过我们模拟发送http请求 var xhr = ( ( window.XMLHttpRequest && (window.location.protocol !== "file:" || !window.ActiveXObject) ) ? function () { return new window.XM

selenium获取元素后用click()点击没有作用,用Keys.ENTER就可以成功

selenium获取元素后用click()点击没有作用,用键盘输入enter(Keys.ENTER)就可以成功 #coding = utf-8 from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Firefox() driver.get("http://www.baidu.com") driver.find_element_by_xpath(&

selenium 代理 Cookies 截图 等待 调用JS

改变用户代理 读取Cookies 调用Java Script Webdriver截图 页面等待 1. 改变用户代理 [java] view plain copy import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver;