I've created a script to log in to a site using IE. What I want to do is when I'm logged in, the script should transfer cookies from IE
to Selenium
so that I can do the browsing using Selenium
.
I can do the login and browsing using IE or Selenium alone but my point here is to learn how to transfer cookies from IE
to Selenium
.
I've tried with:
Sub Login()
Const Url$ = "https://www.facebook.com/"
Dim Htmldoc As HTMLDocument, targetUrl$
Dim elem As Object, posts As Object, collectedcookie
Dim IE As Object: Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.navigate Url
While .Busy = True Or .readyState < 4: DoEvents: Wend
Set Htmldoc = .document
Application.Wait Now + TimeValue("00:00:02")
Htmldoc.querySelector("input[id='email']").Value = "your_username"
Application.Wait Now + TimeValue("00:00:02")
Htmldoc.querySelector("input[id='pass']").Value = "your_password"
Application.Wait Now + TimeValue("00:00:02")
Htmldoc.querySelector("input[value='Log In']").Click
collectedcookie = .document.cookie
targetUrl = IE.LocationURL
.Quit
End With
With New ChromeDriver
.get (targetUrl)
.AddArgument "--cookie=" & collectedcookie
.get (targetUrl)
End With
End Sub
When I execute the above script, I can see that IE can log me in. However, the driver is leading me to the login page again.
Question: How can I transfer cookies from IE to Selenium?
PS The site used within the script is just a placeholder. I chose that site only because most of the login based sites do not support IE nowadays.