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, 2138🔥, 0💬
Popular Posts:
Where to find online test tools? FYIcenter.com has prepared a number of online test tools: Data Look...
How to generate date and time test values? Timestamp values are frequently needed in testing almost ...
How to access Response Status Code 400 as Success? My sampler failed, because the server returns the...
How to perform regular expression pattern match with multiple occurrences? To perform a regular expr...
How to Override a JMeter Variable from Command Line? I want to run the same test plan multiple times...