Posted 11 months 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:

    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.

  2. Visit a URL like this:

    curl http://localhost:9515/session/your-session-id-here/url -d '{"url":""}'
  3. Finding elements is fairly simple:

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

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

    curl -XDELETE http://localhost:9515/session/your-session-id-here

Chromedriver follows the W3C WebDriver spec. There are tons of things you can do with it, but tasks that are simple using something like selenium-webdriver can be quite difficult.
However, for simple debugging or remote-controlling, consider just using curl.

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Owner of this card:

Arne Hartherz
Last edit:
10 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 cookies to improve usability and analyze traffic.
Accept or learn more