python - Create new webdriver session manually -
i trying play little bit webdriver protocol
using python
, requests
module.
i started chromedriver
binary:
$ chromedriver_2.31 starting chromedriver 2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8) on port 9515 local connections allowed.
so far good.
but problem session not created
exception when trying create session:
import requests r = requests.post("http://127.0.0.1:9515/session", {}) print("status: " + str(r.status_code)) print("body: " + str(r.content))
execution output:
status: 200 body: b'{"sessionid":"286421fcd381ee0471418ebce7f3e125","status":33,"value":{"message":"session not created exception: missing or invalid capabilities\\n (driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=linux 4.4.0-91-generic x86_64)"}}'
i searched through webdriver protocol docs, couldn't find information capabilities mandatory or that.
so, tried random capabilities:
import requests data = { "browsername": "chrome", "version": "", "platform": "linux", "javascriptenabled": "true", "acceptinsecurecerts": "false", "cssselectorsenabled": "true" } r = requests.post("http://127.0.0.1:9515/session", data) print("status: " + str(r.status_code)) print("body: " + str(r.content))
but again fail:
status: 400 body: b'missing command parameters'
do have ideas problem , how fix it?
update
also tried:
import requests data = """ { desiredcapabilities: { "browsername": "chrome", "version": "", "platform": "any" } } """ headers = {'content-type': 'application/json'} r = requests.post("http://127.0.0.1:9515/session", json=data, headers=headers) print("status: " + str(r.status_code)) print("body: " + str(r.content))
again error:
status: 400 body: b'missing command parameters'
okay, looked @ how selenium it..:
selenium/webdriver/remote/remote_connection.py
, class remoteconnection
, method execute
. raised exception params, this:
raise exception(params)
here's came out:
{'capabilities': {'alwaysmatch': {'browsername': 'chrome', 'chromeoptions': {'args': [], 'extensions': []}, 'platform': 'any', 'version': ''}, 'firstmatch': []}, 'desiredcapabilities': {'browsername': 'chrome', 'chromeoptions': {'args': [], 'extensions': []}, 'platform': 'any', 'version': ''}}
so, doing same thing, data
our new found dictionary:
r = requests.post('http://127.0.0.1:9515/session', json=data) # new chromium window created r.content `b'{"sessionid":"94cf6af9577d323eb51f6340b1fd2d07","status":0,"value":{"acceptsslcerts":true,"applicationcacheenabled":false,"browserconnectionenabled":false,"browsername":"chrome","chrome":{"chromedriverversion":"2.30.477729 (e5aa99d9d101379b1542958a71df3f50913f1ea2)","userdatadir":"/tmp/.org.chromium.chromium.uqwviv"},"cssselectorsenabled":true,"databaseenabled":false,"handlesalerts":true,"hastouchscreen":false,"javascriptenabled":true,"locationcontextenabled":true,"mobileemulationenabled":false,"nativeevents":true,"networkconnectionenabled":false,"pageloadstrategy":"normal","platform":"linux","rotatable":false,"takesheapsnapshot":true,"takesscreenshot":true,"unexpectedalertbehaviour":"","version":"60.0.3112.78","webstorageenabled":true}}'`
Comments
Post a Comment