How to control Chromedriver using curl
selenium-webdriver
. This can be useful for debugging.1. download chromedriver.exe on windows/mac, go to the same directory and run this command:
On Mac: ./chromedriver &
On Windows: chromedriver.exe
2. Create a session:
Java Code:
WebDriver driver = new ChromeDriver();
Curl Command:
curl -XPOST http://localhost:9515/session -d ‘{“desiredCapabilities”:{“browserName”:”chrome”}}’
3. launch a URL:
Java Code:
driver.get(“https://www.google.com”);
Curl Command:
curl http://localhost:9515/session/142a7f9bb57b8fda48636c8709df9591/url -d ‘{“url”:”https://www.google.com”}’
4. find an element:
Java Code:
WebElement element = driver.findElement(By.name(“q”));
Curl Command:
curl http://localhost:9515/session/142a7f9bb57b8fda48636c8709df9591/element -d ‘{“using”:”name”, “value”:”q”}’
5. enter text in element:
Java Code:
element.sendKeys(“Naveen AutomationLabs”);
Curl Command:
curl http://localhost:9515/session/142a7f9bb57b8fda48636c8709df9591/element/0.45843488917986774-1/value -d ‘{“value”:[“Naveen Automation Labs”]}’
6. Quit Browser/close the session:
Java Code:
driver.quit();
Curl Command:
curl -X DELETE http://localhost:9515/session/142a7f9bb57b8fda48636c8709df9591
Cheers!!
Naveen AutomationLabs