1. 程式人生 > >selenium獲取cookies

selenium獲取cookies

2.3 tab validator framework comm connect expires anim sid

<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

selenium獲取cookies