So I have coded this script that sets a session then goes through a series of requests but at the end of the final request, I would like it to launch a (headless and) browser on the same session at the beginning then I will further automate processes.
Asked
Active
Viewed 96 times
-1
-
could You please share the code? I didnt get the question – eugene.polschikov May 12 '19 at 08:59
-
The code is a bit private but, so the general gist of it is, at the beginning i have – Tony May 12 '19 at 09:01
-
s = requests.session() – Tony May 12 '19 at 09:01
-
then i def a couple functions, all the functions then run within this one session – Tony May 12 '19 at 09:02
-
All the functions are, request based and now I would like to transition the session from requests to browser – Tony May 12 '19 at 09:03
-
Please, edit your comments into a single comment, or put that information in the question itself. And in the meantime, try taking a look at [this page](https://www.guru99.com/handling-cookies-selenium-webdriver.html) about how to add cookies into selenium driven browser. I think that cookies are the most significant part of "transferring sessions" – Faboor May 12 '19 at 09:15
1 Answers
0
@Tony, apologies in advance if I misunderstood anything from the question - but basically task breaks down to transferring selenium session (cookies including sessionId if any) to selenium instance.
Recently I implemented similar solution in java bindings: had to extract cookies from selenium driver instance and had to put them in rest-assured client instance for further API requests execution.
log.info("exctacting cookies from driver instance...... To use cookies for api requests");
Map<String, String> cookies = new HashMap<String, String>();
// init cookies for resassured
Set<Cookie> driverCurrentCookies = driver.manage().getCookies();
for (Cookie c : driverCurrentCookies) {
cookies.put(c.getName(), c.getValue());
}
log.info("cookies extracted: " + cookies.toString());
In Your case- You need to do inversion (idea at high level). Need to see Your code to provide more details

eugene.polschikov
- 7,254
- 2
- 31
- 44