Skip to content

Instantly share code, notes, and snippets.

@andrewnicols
Created December 12, 2019 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewnicols/7034a5c1da06eba69401f4c09eb2460b to your computer and use it in GitHub Desktop.
Save andrewnicols/7034a5c1da06eba69401f4c09eb2460b to your computer and use it in GitHub Desktop.
#!/bin/bash
WDURL="http://localhost:9515";
#RESPONSE=`curl -s -d '{"capabilities": {"firstMatch": [{"acceptInsecureCerts": false, "browserName": "chrome"}]}}' "${WDURL}/session"`
RESPONSE=`curl -s -d '{"capabilities": {"firstMatch": [{"acceptInsecureCerts": false, "browserName": "chrome", "goog:chromeOptions": {"args": ["-headless"]}}]}}' "${WDURL}/session"`
SESSIONID=`echo "${RESPONSE}" | python3 -c "import sys, json; print(json.load(sys.stdin)['value']['sessionId'])"`
echo "Setting URL:"
curl -d '{"url":"http:\/\/localhost\/date.html"}' "${WDURL}/session/${SESSIONID}/url"
echo
echo "Getting element ID"
ELEMENTID=`curl -s -d '{"using": "css selector", "value": "#dateval"}' "${WDURL}/session/${SESSIONID}/element" | \
python3 -c "import sys, json; print(json.load(sys.stdin)['value']['element-6066-11e4-a52e-4f735466cecf'])"`
echo
echo "Getting current document.visibilityState"
curl -d '{"script": "return document.visibilityState;", "args": []}' "${WDURL}/session/${SESSIONID}/execute/sync"
echo
echo "Minimizing"
curl -d '{}' "${WDURL}/session/${SESSIONID}/window/minimize"
echo
echo "Getting updated document.visibilityState"
curl -d '{"script": "return document.visibilityState;", "args": []}' "${WDURL}/session/${SESSIONID}/execute/sync"
echo
echo "Deleting window:"
curl -X DELETE "${WDURL}/session/${SESSIONID}/window"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment