In theory, if I copy all of the cookies from selenium's webdriver
object to requests.Session
object, would requests be able to continue on as if the session was not interrupted?
Specifically, I am interested in writing automation where I get to 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)
Extends Selenium WebDriver classes to include the request function from the Requests library, while doing all the needed cookie and request headers handling.
Using Requests generally results in faster and more concise code, while using Selenium makes development faster on Javascript heavy sites.
New Selenium IDE To create multiple sessions, we shall add the attributes – parallel and thread-count in the XML file. The attribute thread-count controls the number of sessions to be created while executing the tests in a parallel mode. The value of parallel attribute is set to methods.
Session object allows one to persist certain parameters across requests. It also persists cookies across all requests made from the Session instance and will use urllib3's connection pooling.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With