Collections:
Start Browser with ChromeDriver WebDriver
How to start a new browser session with ChromeDriver WebDriver server?
✍: FYIcenter.com
You can start a new browser session with ChromeDriver WebDriver server
using the "POST /session" service
as shown in this tutorial.
1. Make sure Python is installed:
C:\fyicenter> python --version Python 3.7.4
2. Make sure Python "requests" module is installed:
C:\fyicenter> pip install requests Collecting requests Collecting idna<2.9,>=2.5 (from requests) Collecting chardet<3.1.0,>=3.0.2 (from requests) Collecting certifi>=2017.4.17 (from requests) Installing collected packages: idna, chardet, certifi, requests Successfully installed certifi-2019.6.16 chardet-3.0.4 idna-2.8 requests-2.22.0
3. Start ChromeDriver WebDriver server with logging turned on listening on port 9515.
C:\fyicenter> \fyicenter\selenium\chromedriver\chromedriver.exe --verbose Starting ChromeDriver 75.0.3770.90 (...-refs/branch-heads/3770@{#1003}) on port 9515
4. Enter the following Python script in a separate window to start a new browser session by sending a "POST /session" request:
C:\fyicenter> type PostSessionChrome.py # PostSessionChrome.py # Copyright (c) FYIcenter.com import requests data = """ { "capabilities": { "alwaysMatch": { "browserName": "chrome", "goog:chromeOptions": { "args": [ ], "extensions": [ ] }, "platformName": "any" }, "firstMatch": [ { } ] }, "desiredCapabilities": { "browserName": "chrome", "goog:chromeOptions": { "args": [ ], "extensions": [ ] }, "platform": "ANY", "version": "" } } """ res = requests.post("http://localhost:9515/session", data) print("Status: " + str(res.status_code)) print("Body: " + str(res.content))
5. Run the Python script:
C:\fyicenter> python PostSessionChrome.py Status: 200 Body: b'{ "value": { "capabilities": { "acceptInsecureCerts": false, "browserName": "chrome", "browserVersion": "75.0.3770.142", "chrome": { "chromedriverVersion": "75.0.3770.90 (...-refs\/branch-heads\/3770@{#1003})", "userDataDir": "C:\\Users\\fyicenter\\AppData\\Local\\Temp\\scoped_dir70244_21653" }, "goog:chromeOptions": { "debuggerAddress": "localhost:63448" }, "networkConnectionEnabled": false, "pageLoadStrategy": "normal", "platformName": "windows nt", "proxy": {}, "setWindowRect": true, "strictFileInteractability": false, "timeouts": { "implicit": 0, "pageLoad": 300000, "script": 30000 }, "unhandledPromptBehavior": "dismiss and notify" }, "sessionId": "d1e9fd4561397db9b4deb2cb5bbd0dbf" } }'
You should see that WebDriver server starts a new session with a new Chrome window started.
See the next tutorial on how load a Web page in a new session.
⇒ Load Web Page in ChromeDriver WebDriver Session
⇐ Start ChromeDriver WebDriver Server
2019-12-02, 1959🔥, 0💬
Popular Posts:
How to turn on Chrome WebDriver logging with Selenium Python API? If you want to turn on logging on ...
What are date and time test values? Date and time test values are frequently needed in testing date ...
How to generate IP Addresses? To help you to obtain some IP addresses for testing purpose, FYIcenter...
How to find out my browser request headers? To help you to see your browser request headers, FYIcent...
How to validate email address format? In order to help your programming or testing tasks, FYIcenter....