I am using Selenium to log in to some website via EDGE.
The browser window is closing.
How can I stop the window from closing?
Sub Login_EdgeChrome2()
Dim wd As WebDriver
Set wd = New ChromeDriver
Const URL = "https://mms.fsicloud.me/Evolution/!System/Security/Login.aspx?ReturnUrl=%2fEvolution"
With wd
.Start "Edge"
.Get URL
.FindElementById("ctl00_contentPlaceHolder_loginControl_UserName").SendKeys "username"
.FindElementById("ctl00_contentPlaceHolder_loginControl_Password").SendKeys "password"
.FindElementById("ctl00_contentPlaceHolder_loginControl_LoginButton").Click '- this will log in with the correct credentials.
End With
wd.Wait (Now + TimeValue("00:01:30"))
End Sub
Used to do this in IE. However some features don't work well now in IE.
I tried Selenium to log in via EDGE. However, it logs automatically. So I put the time delay, but after the time lapsed, it will close again.
I confess I don't know much about VB - but from the looks of it, you have a subroutine that creates a localized instance of WebDriver. So when Login_EdgeChrome2 ends, the local instance disappears. In my world (in the languages I am familiar with), I'd have to return wd as a result of that subroutine to make it "survive".
Related
Hi I am trying to write a scraper to get data from this website (www.coned.com/tcisng) and dump data into my Ms Access Backend. When I navigate to it and enter in my credentials (username and password), it does not activate the "Log In" button which I want to click next as it is the next step on my scraper. Also this "Log In" button has no name or ID. How to activate and make it click using VBA in Ms Access 2016.
Updated Code Snippet -
Dim ie As Object
Set ie = CreateObject("internetexplorer.application")
ie.Visible = True
ie.Navigate "www.coned.com/tcisng"
While ie.Busy
DoEvents
Wend
Do
DoEvents
Loop Until ie.ReadyState = READYSTATE_COMPLETE
ie.Document.all("LoginEmail").Value = "myemail"
ie.Document.all("LoginPassword").Value = "myPassword"
Do
DoEvents
Loop Until ie.ReadyState = READYSTATE_COMPLETE
While ie.Busy
DoEvents
Wend
'ie.Document.all(48).Click
'ie.Document.querySelector("[type=submit]").Click
ie.Document.querySelector("button[title*='Log in']").Click
In the last 3 line I am trying to select the "Log In" button but it is disabled, also it has no name or ID, can you also help what exact code to replace in order to activate the button and click it later.
Instead of trying to "click" the button, try submitting the form. The Javascript for that ConEdison page would be:
document.getElementById("form-login-email").form.submit()
In the "old days", with just a plain form, this would work fine.
But on that website there is a lot more going on. That email input element has nine events attached to it. By just filling in the value, you aren't triggering any of those events.
With forms built with ReactJS, for example, the user's interaction with the Input element is monitored, and the value is extracted and stored in a non-displaying object in the DOM tree. When the Submit button is clicked, the form's visible Input elements may not be used at all. In order to feed inputs into such forms, you need to understand ReactJS data structures, and manipulate them directly.
I recently built a scraper based on Chromedriver, which allows a Chrome browser window to be controlled from an external program, such as Access VBA. Once started, Chromedriver runs as a mini-webserver on localhost, and commands sent to it from Access VBA (through a ServerXMLHTTP60 object) cause it to launch Chrome, visit a URL, send keystrokes to input elements etc. Within the browser, the keystrokes fire all the events that human keystrokes would do. The target website was ReactJS-based, but I was able to ignore all of the internal complexity of ReactJS.
Since the website runs in a regular Chrome browser, I was able to use F12 Developer Tools in the development process.
The technology is Webdriver, and was developed for building website testing tools. There are Firefox and MS Edge Chromium versions as well.
I am currently using Office 2010, Visual Basic for Applications 7, and Internet Explorer 9.
The current issue I've been having is that using an IE object seems to fail on our intranet, and I was wondering if there was a fix for this.
Functioning code:
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "http://www.google.com"
WaitUntilReady IE
'Application.Wait (Now + TimeValue("00:00:10"))
'IE.Visible = True
MsgBox (IE.Document.body.innerHTML)
Broken code:
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "http://intranet/"
WaitUntilReady IE
'Application.Wait (Now + TimeValue("00:00:10"))
'IE.Visible = True
MsgBox (IE.Document.body.innerHTML)
Functioning code does exactly what it should. Makes an IE object which doesn't show up visibly on screen, and returns a message box with the HTML code contents of google.com
Broken code loads our intranet home page, in a VISIBLE IE window, and returns this error:
Run-time error '-2147417848 (80010108)'
Automation error
The object invoked has disconnected from its clients
I've read through Excel VBA Controlling IE local intranet which suggested using an IP address instead of intranet/ which doesn't work because the IP directs to a different splash screen.
I've also tried using
Set IE = New InternetExplorerMedium
But this A- didn't seem to work either, and B- would mean making sure all my fellow employees enable this Reference.
Also, I've tried loading google.com first, then having it navigate to intranet/, which also didn't help.
Anyone have any suggestions? From my understanding, loading intranet/ is causing IE to disconnect from Excel somehow?
SO! After several days of research and at a complete loss for what was going on, I stumbled on to someone talking about intranet compatibility mode in another article.
Force "Internet Explorer 8" browser mode in intranet
Things happened to click in my head when I read this, realizing that if IE loaded in compatibility, it would explain why the Excel VBA macro lost control of IE, as compatibility mode might be loading as a separate instance of IE.
Settings > Internet Options > Security > Local Intranet > Sites >
Disable "Auto detect intranet" and enable "Include all network paths (UNCs)" fixes the error I was having, perfectly.
'simply replace -seem to work
' Set ie = CreateObject("InternetExplorer.Application")
Set ie = New InternetExplorerMedium
another solution
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate ("http://URLOnMyIntranet/site.html")
IE.Visible = True
Set IE = nothing
Set objShellApp = CreateObject("Shell.Application")
For Each objWindow In objShellApp.Windows
Debug.Print objWindow.LocationName
If LCase(objWindow.LocationName) = LCase("Your windows name, use debug to find out") Then
Set IE = objWindow
End If
Next`enter code here`
also see this post
I have some code that retrieves data from multiple websites via Internet Explorer automation in VBA. My code worked without problems with IE8, but in IE11, after the Navigate method of the Internet Explorer object is called, the Document and LocationURL are not updated; they still refer to the previously displayed website. Here's some code to reproduce the problem:
Sub Test()
Debug.Print "start"
Dim ie
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "http://en.wikipedia.org/wiki/Visual_Basic"
wait ie
Debug.Print "Current URL: " & ie.LocationURL
ie.Navigate "http://en.wikipedia.org/wiki/Microsoft_Office"
wait ie
Debug.Print "Current URL: " & ie.LocationURL
Set ie = Nothing
End Sub
Sub Wait(ie As Variant)
Do While ie.Busy
Application.wait DateAdd("s", 1, Now)
Loop
End Sub
When a run the above Test sub on a machine with IE8, it prints two different URLs, which is the expected behavior. However, when I run the same code on a machine with IE11, it prints the first URL twice. Any idea what might be wrong?
Update: I couldn't find a solution, so I went for the workaround of opening a new IE window for each URL.
I am not familiar with the VBA IE automation that you are using, however it sounds like you are hitting the same issue as Selenium WebDriver on IE11.
You may need to follow the same steps provided by the in the Selenium Wiki.
For IE 11 only, you will need to set a registry entry on the target
computer so that the driver can maintain a connection to the instance
of Internet Explorer it creates. For 32-bit Windows installations, the
key you must examine in the registry editor is
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet
Explorer\Main\FeatureControl\FEATURE_BFCACHE. For 64-bit Windows
installations, the key is
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet
Explorer\Main\FeatureControl\FEATURE_BFCACHE. Please note that the
FEATURE_BFCACHE subkey may or may not be present, and should be
created if it is not present. Important: Inside this key, create a
DWORD value named iexplore.exe with the value of 0.
http://code.google.com/p/selenium/wiki/InternetExplorerDriver
Hopefully that fixes your problem!
THX, You helped me.
W7 Ultimate 64bit czech, IE11, VBA in Microstation V8i
I use code like:
Public explorer As Object
....
Set explorer = CreateObject("InternetExplorer.Application")
....
If InStr(explorer.LocationURL, "CAPTCHA") = 0 Then
...
End If
I have setup a userform1 to browse an intranet using web browser controls in VBA/Excel. The problem I am having is that when the user initiates a popup through the web browser control, that popup runs in IE by default, outside of the scope of the web browser control, and therefore doesnt contain the correct session data in the popup. This popup initiates from a dropdown box, onchange command and then inserts the input from the popup back into a web form on the page. The code below intercepts the popup event and lets you handle it, by transferring it to say, userform2
Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
Dim frm As UserForm2
'Dim ppDisp As Object
Set frm = New UserForm2
Set ppDisp = frm.WebBrowser1.Application
frm.Show
End Sub
Problem is, it gets stuck right now on frm.show, when I pause, and doesnt seem to be actively transferring over the web page correctly into userform2. I'm not sure where my logic is wrong here, any advice would be helpful. Most guides have shown:
Set ppDisp = frm.WebBrowser1.object
But I cant find that in the object browser anywhere, and doing .object bombs out, as error 438: object doesnt support this property or method. But everything I could find on this so far shows using .object.
for anyone reading this, VBA wont support this method as the above says. It works perfectly in .net and I would assume then, vb6
I have a VB.Net app that needs to print a bunch of pages from a secure intranet site; the app was made and was working for a non-secure site but now the app needs to login before accessing the web pages necessary to print.
I get the error "Object Reference not set to an instance of an object" when I use my new Sub which follows:
Private Sub SiteLogin()
WebBrowser1.Navigate("http://url/login/")
WebBrowser1.Document.GetElementById("user").SetAttribute("value", "username")
WebBrowser1.Document.GetElementById("password").SetAttribute("value", "mypassword")
WebBrowser1.Document.GetElementById("submit").InvokeMember("click")
End Sub
I got the code from this VB tutorial, but I seem to be missing something in how I'm referencing the WebBrowser.Document object. I've never used VB.Net before so I don't know much about this problem, I have the following sub which DOES work from the original program however:
Private Sub WebPrint()
WebBrowser1.Navigate(strUrl)
WebDocLoaded = False
'lblMessage.Text = "Waiting for report page to load"
Do Until WebDocLoaded
System.Windows.Forms.Application.DoEvents()
Loop
End Sub
This Sub prints the given page in IE, so I figured I could use the same WebBrowser1 object for the login Sub, as I don't know how to or whether I should declare a separate object for the SiteLogin Sub. Both of these functions are called after the WebBrowser1 object is defined however.
I just need to be able to submit a simple login form to a set URL, and this info needs to all be hardcoded (there's no option to set the location or login info nor should there be). If there's another way to log into this site via VB.Net or if I need to give more information let me know.
.Navigate returns before the page load is complete so the DOM is not ready & .Document is not accessible.
See; How to wait until WebBrowser is completely loaded in VB.NET?