39
bash で Web でででで (Selenium WebDriver) でででででで でででで

bashでWebブラウザ(Selenium WebDriver)を動かした話

  • Upload
    -

  • View
    1.173

  • Download
    0

Embed Size (px)

Citation preview

OSC?

bashWeb(Selenium WebDriver)

Selenium?34Se16217.4

3

3

Selenium?http://docs.seleniumhq.org/WebApache 2.0 License

Selenium WebDriverhttp://docs.seleniumhq.org/projects/webdriver/WebMozilla Firefox, Google Chrome(Linux, Windows, MacOS, Android), Internet Explorer, Safari, EdgeJava, Ruby, Python, C#, Javascript(Node.js)OSLinux, MacOS, Windows

SeleniumClientFirefoxDriver

ChromeDriver

IEDriver

MicrosoftEdgeDriver

SeleniumServer

ChromeDriverHTTP

(JSON)HTTP

(JSON)

bash

8

8

ChromeDriverHTTP

(JSON)HTTP

(JSON)curl

SeleniumServer

Selenium Server $ DISPLAY=:0.0 java jar selenium-server-standalone-2.53.1.jar -Dwebdriver.chrome.driver=/path/to/chromedriver -Dwebdriver.ie.driver=/path/to/IEdriver -Dwebdriver.edge.driver=/path/to/MicrosoftWebDriver

DISPLAY/path/to/chromedriver /path/to/Iedriver

jarchromedriverhttp://www.seleniumhq.org/download/

curl?

http://www.suruga-ya.jp/product/detail/980001420000

12

12

curlcurl(1)curl , DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET, TFTP

curlcurl [options] [URL...]RESPONSE=\ $(curl --request " \ --data (JSON)' \ "APIURL")

APIhttps://w3c.github.io/webdriver/webdriver-spec.htmlcurl

Selenium WebDriverAPI ()URIPOST/sessionPOST/session/{session id}/urlURLGET/session/{session id}/titlePOST/session/{session id}/elementPOST/session/{session id} /element/{element id}/sendKeysPOST/session/{session id} /element/{element id}/click

https://w3c.github.io/webdriver/webdriver-spec.html

16

16

WebGoogleOSS~

BPhttp://itpro.nikkeibp.co.jp/article/COLUMN/20131003/508665/

Web(Mozilla Firefox)RESPONSE=$(curl --request "POST" \ --data \ '{"desiredCapabilities":\ {"browserName":"firefox},\ "requiredCapabilities":{}}' \ "http://localhost:4444/wd/hub/session")# IDSESSION_ID=$(echo ${RESPONSE} | \ sed -e 's/^.*"sessionId":"\([^"]*\)".*/\1/g')

curl{ "state": null, "sessionId": "45314279-a985-4a7e-aee1- 30582a4f9c2a", "hCode": 682306787, "value": { "applicationCacheEnabled": true, "rotatable": false, "handlesAlerts": true, "databaseEnabled": true, "version": "46.0.1", "platform": "WINDOWS", "nativeEvents": false, "acceptSslCerts": true,

"webdriver.remote.sessionid": "45314279-a985-4a7e-aee1- 30582a4f9c2a", "webStorageEnabled": true, "locationContextEnabled": true, "browserName": "firefox", "takesScreenshot": true, "javascriptEnabled": true, "cssSelectorsEnabled": true }, "class": "org.openqa.selenium.remote. Response", "status": 0}

Web(Google Chrome)RESPONSE=$(curl --request "POST" \ --data \ '{"desiredCapabilities":\ {"browserName":chrome},\ "requiredCapabilities":{}}' \ "http://localhost:4444/wd/hub/session")# IDSESSION_ID=$(echo ${RESPONSE} | \ sed -e 's/^.*"sessionId":"\([^"]*\)".*/\1/g')

Web(Internet Explorer)RESPONSE=$(curl --request "POST" \ --data \ '{"desiredCapabilities":\ {"browserName":internet explorer},\ "requiredCapabilities":{}}' \ "http://localhost:4444/wd/hub/session")# IDSESSION_ID=$(echo ${RESPONSE} | \ sed -e 's/^.*"sessionId":"\([^"]*\)".*/\1/g')

Web(Microsoft Edge)RESPONSE=$(curl --request "POST" \ --data \ '{"desiredCapabilities":\ {"browserName":MicrosoftEdge},\ "requiredCapabilities":{}}' \ "http://localhost:4444/wd/hub/session")# IDSESSION_ID=$(echo ${RESPONSE} | \ sed -e 's/^.*"sessionId":"\([^"]*\)".*/\1/g')

Web(Google Chrome on Android)RESPONSE=$(curl --request "POST" \ --data \ '{"desiredCapabilities":\ {"browserName":"chrome, \ "chromeOptions": {"androidPackage": \ "com.android.chrome"}},\ "requiredCapabilities":{}}' \ "http://localhost:4444/wd/hub/session")# IDSESSION_ID=$(echo ${RESPONSE} | \ sed -e 's/^.*"sessionId":"\([^"]*\)".*/\1/g')

Googlecurl --request "POST" \ --data '{"url":http://www.google.co.jp"}' \http://localhost:4444/wd/hub /session/"${SESSION_ID}"/url"#() URI

GoogleRESPONSE=$(curl --request "POST" \ --data '{"using":"name,value:q} \http://localhost:4444/wd/hub /session/"${SESSION_ID}"/element")# ()URI

# ELEMENT_IDIDELEMENT_ID=$(echo ${RESPONSE} | \ sed -e 's/^.*"ELEMENT":"\([^"]*\)".*$/\1/g')

curl{ "state": "success", sessionId: "da990f64-671f-4b4e-b4f9-af3363fb54e8", "hCode": 1209818291, "value": { "ELEMENT": "0" }, "class": "org.openqa.selenium.remote.Response", "status": 0} successID

STATE=""while [ "${STATE}" != "success" ]do RESPONSE=$(curl --request "POST" \ --data '{"using":"'${SELECTOR}'","value":"'${LOCATOR}'"}' \ http://localhost:4444/wd/hub/session/"${SESSION_ID}"/element") STATE=$(echo ${RESPONSE} | \ sed -e 's/^.*"state":"\([^"]*\)".*$/\1/g')doneELEMENT_ID=$(echo ${RESPONSE} | \ sed -e 's/^.*"ELEMENT":"\([^"]*\)".*$/\1/g')

curl --request "POST" \ --data {value:[\n"]}' \"http://localhost:4444/wd/hub /session/"${SESSION_ID}" /element/"${ELEMENT_ID}"/value"#() URI

(Edge)Javascriptcurl --request "POST" \ --data {script:elements = document.getElementsByName(\"q\"); elements[0].value=\"\";", "args":[]}' \ http://localhost:4444/wd /hub/session/${SESSION_ID}"/execute/sync"#() URIJavascript

(Edge)JavascriptSubmitcurl --request "POST" \ --data {script:elements = document.getElementsByName(\f\); elements[0].submit();, args:[]} \ http://localhost:4444/wd/hub /session/${SESSION_ID}/execute/sync#() URIJavascript

TITLE=""while [ "${TITLE}" != " - Google " ]do RESPONSE=$(curl --request "GET" \http://localhost:4444/wd/hub /session/${SESSION_ID}/title)#() URI TITLE=$(echo ${RESPONSE} | \sed -e 's/^.*"value":"\([^"]*\)".*$/\1/g')done

RESPONSE=$(curl --request "POST" \ --data '{"using":"partial link text,\ value:OSS} \http://localhost:4444/wd/hub /session/"${SESSION_ID}"/element")# () URI

# ELEMENT_IDIDELEMENT_ID=$(echo ${RESPONSE} | \ sed -e 's/^.*"ELEMENT":"\([^"]*\)".*$/\1/g')

curl --request "POST" \http://localhost:4444/wd/hub /session/${SESSION_ID} /element/${ELEMENT_ID}/click# () URI

34

34

35

35

WebGoogleOSS~

BPhttp://itpro.nikkeibp.co.jp/article/COLUMN/20131003/508665/

bashGoogle Chrome

bashWeb(Selenium WebDriver)Selenium ServercurlHTTPSelenium ServerJSON

(^.^)/~~~

39