Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
3 views
in DevOps and Agile by (19.7k points)

In theory, if I copy all of the cookies from selenium's webdriver object to requests.Sessionobject, would request be able to continue on as if the session was not interrupted?

Specifically, I am interested in writing automation where I get to a specific location on the webpage via selenium, then pass on a certain download link to requests, which would download and verify specific bytes out of the file, and sometimes a full file. (The value of the file downloaded would change based on my interaction in selenium)

1 Answer

0 votes
by (62.9k points)

Yes it will definitely work. Following code, snippet should help as well -

headers = { "User-Agent": "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36" } s = requests.session() s.headers.update(headers) for cookie in driver.get_cookies(): c = {cookie['name']: cookie['value']} s.cookies.update(c)

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, you should enroll yourself in industry-based Selenium online courses

by (100 points)
What if you want to do the exact opposite?
You carry some tasks with requests and then open the browser with the session that you worked on from the beginning?

Browse Categories

...