Using VBA to complete pop-up form in IE

ANRoebuck

New Member
Joined
Nov 21, 2018
Messages
5
I'm trying to build a macro to go to a website, log in to an account, and retrieve data. The login form isn't on the web page as soon as it loads - you have to click a button first to make the form pop up. I'm getting an "object required" error message on the final line of the code below, even though I'm sure I have the correct object ID for the username field on the pop-up form.


Code:
'Open IE and navicate to login page
Set IE = New InternetExplorer
IE.Visible = True
IE.navigate URL
Do Until IE.readyState = READYSTATE_COMPLETE: DoEvents: Loop




'Click login button to open form
Dim bLogIn As Object: Set bLogIn = IE.document.getElementById("SignInButton")
bLogIn.Click
Do Until IE.readyState = READYSTATE_COMPLETE: DoEvents: Loop




'Enter login info
IE.document.getElementById("username").Value = User


Inspecting the username field gives:

HTML:
<input class="textbox" data-state="0" data-val-error-location=".error-summary.title" data-val-invokable="true" data-val-invokable-event="login-fail" data-val-login-fail-error="Something's not quite right; please try again." data-val-required="true" data-val-required-error="This is a required field." id="username" maxlength="80" name="username" rel="0" type="text" value="">


If it's helpful to look at the website in question, you can see that at the link below. Pressing "Sign in" in the top right corner brings up the login form.

https://www.wizards.com/Magic/PlaneswalkerPoints/


Any ideas what I'm missing? Any help would be very much appreciated!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I'm not an expert in handling IE objects but it appears that pop up form is a frame. Do you need to reference the frame then the object?

When I ran your code the website gave an error saying the user site was down. But when I step through the code the login form appears. Weird.

I think the last line needs to look something like this:

IExplorer.Document.Frames("Enter frame name here").Document.getElementById("username").Value = User
or
IExplorer.Document.Frames("Enter frame name here").ContentDocument.getElementById("username").Value = User

It looks like the frame name is "samlWidget". I think the frame is an "iframe" - I'm unsure if that makes a difference or not....


 
Upvote 0
I've managed to identify where the box to enter the username is in the HTML - it's nested several layers deep. I've put each of the nested elements in the box below; each item in the list is nested within the one above, and it's the last item that I'm trying to isolate. I've managed to get it to select the first two, but anything deeper I'm having no luck with.


Code:
******** id="wotcAccountWidgetModalIframe" src="https://accounts.wizards.com/Widget/ShowLogin?returnUrl=https%3A%2F%2Fwww.wizards.com%2FMagic%2FPlaneswalkerPoints%2F&requiredFieldSets=playlocation+name" class=" wotcWidget-modalIFrame" style="z-index: 1;">*********>
 
 
<html class="accounts-modal-html">
 
 
****** class="modal-body" >
 
 
<div class="modal">
 
 
<div class="modalFrame">
 
 
<div class="margin15Area">
 
 
<div class="modalContent">
 
 
<form id="loginForm" novalidate="">
 
 
<div class="control-container">
 
 
<div style="display: table;" class="textBoxHelpWrapper">
 
 
<input class="textbox" data-state="0" data-val-error-location=".error-summary.title" data-val-invokable="true" data-val-invokable-event="login-fail" data-val-login-fail-error="Something's not quite right; please try again." data-val-required="true" data-val-required-error="This is a required field." id="username" maxlength="80" name="username" rel="0" type="text" value="">
 
 
      ‘back at pink level
<div class="control-container">
 
 
<div style="display: table;" class="textBoxHelpWrapper">
 
 
        <input class="textbox" data-state="0" data-val-error-location=".error-summary.title" data-val-invokable="true" data-val-invokable-event="login-fail" data-val-login-fail-error="Something's not quite right; please try again." data-val-required="true" data-val-required-error="This is a required field." id="password" maxlength="29" name="password" rel="0" type="password" value="">



The code that seems to be happy picking out the first two layers is below.

Code:
Set Doc1 = IE.document.getElementById("wotcAccountWidgetModalIframe")
    Set Doc1 = Doc1.document.getElementsByClassName("accounts-modal-html")(0)


Trying to isolate any of the other elements hasn't worked for me though and I'm not sure why.
 
Upvote 0
I've put each of the nested elements in the box below; each item in the list is nested within the one above, and it's the last item that I'm trying to isolate.

I pasted more than I meant to - please ignore the last three elements in that box.

Also apparently you can't edit your posts on this forum?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top