Posted over 3 years ago. Visible to the public. Linked content.

How to control Chromedriver using curl

Here is how to use Chromedriver without libraries like selenium-webdriver. This can be useful for debugging.

The following example visits a web page and reads the a headline's text contents.

  1. Create a session:

    Copy
    curl -XPOST http://localhost:9515/session -d '{"desiredCapabilities":{"browserName":"chrome"}}'

    You will get a JSON response containing lots of information about your Chrome session, including a sessionId. Use this to send any future commands to your chromedriver session.

    Copy
    {"sessionId":"your-session-id-here","status":0,"value":{...}}
  2. Visit a URL like this:

    Copy
    curl http://localhost:9515/session/your-session-id-here/url -d '{"url":"http://example.com/"}'
    Copy
    {"sessionId":"...","status":0,"value":null}
  3. Finding elements is fairly simple:

    Copy
    curl http://localhost:9515/session/your-session-id-here/element -d '{"using":"tagName","value":"h1"}'
    Copy
    {"sessionId":"...","status":0,"value":{"ELEMENT":"element-object-id-here"}}
  4. Read the element's text content by using the element's identifier received above:

    Copy
    curl http://localhost:9515/session/your-session-id-here/element/element-object-id-here/text
    Copy
    {"sessionId":"...","status":0,"value":"Example Domain"}
  5. To close Chrome, terminate your session:

    Copy
    curl -XDELETE http://localhost:9515/session/your-session-id-here
    Copy
    {"sessionId":"...","status":0,"value":null}

Chromedriver follows the W3C WebDriver spec. There are tons of things you can do with it, but performing more advanced tasks without a tool like selenium-webdriver can be quite difficult.
However, for simple debugging or remote-controlling, curl might be an adequate option.

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for old versions of Ruby on Rails (3.2 and 2.3).

Owner of this card:

Avatar
Arne Hartherz
Last edit:
9 months ago
by Arne Hartherz
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Arne Hartherz to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more