Last active
January 24, 2018 14:54
-
-
Save andygarfield/ffacd8289895c0f249dbfc43a134cc15 to your computer and use it in GitHub Desktop.
Curl Webdriver Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# jq is a dependency and ChromeDriver needs to be running | |
# Create a headless Chrome session and save the sessionId to variable SID | |
SID=$(curl -X POST -d '{"desiredCapabilities":{"browserName":"chrome","chromeOptions":{"args":["--headless"]}}}' http://localhost:9515/session | jq -r '.sessionId') | |
echo "Session ID: $SID" | |
# Point session to a webpage | |
curl -X POST -d '{"url":"http://localhost:8080"}' "http://localhost:9515/session/$SID/url" | |
# Fetch an element using the xpath selector and save the elementId to ELEM | |
ELEM=$(curl -X POST -d '{"using": "xpath", "value": "//a[contains(.,'"'"'CSV format (.csv)'"'"')]"}' "http://localhost:9515/session/$SID/elements" | jq -r '.value[0].ELEMENT') | |
# Get the href attribute | |
curl "http://localhost:9515/session/$SID/element/$ELEM/attribute/href" | jq -r '.value' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment