VBA I can't interact with the elements on the next page after I log in
up vote
0
down vote
favorite
Ok so I have my excel VBA macro longing into my site and from the landing I direct it to a search page but I'm getting This Error after IE gets to the search page. I thought resetting the objcollection on the new page would work but I don't know how to set focus or select the new page or what... I new to using VBA with IE for automation sorry if it's super obvious.
Sub GoToWebsiteTest2()
Dim appIE As InternetExplorerMedium
Dim objElement As Object
Dim objCollection As Object
Set appIE = New InternetExplorerMedium
sURL = "https://example.login.aspx"
With appIE
.Navigate sURL
.Visible = True
End With
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
Set objCollection = appIE.Document.getElementsByTagName
'Set appIE = Nothing
appIE.Document.getElementById("txtUsername").Value = "user"
appIE.Document.getElementById("txtPassword").Value = "Pass"
appIE.Document.getElementById("btnLogin").Click
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
appIE.Navigate "https://example.Search.aspx"
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
Set objCollection = appIE.Document.getElementsByTagName
*appIE.Document.getElementById("txtNum").Value = "0000000"*
appIE.Document.getElementById("btnSearch").Click
End Sub
I changed it to this and it worked great the elements were in an iframe
Sub GoToWebsiteTest2()
Dim appIE As InternetExplorerMedium
Dim objElement As Object
Dim objCollection As Object
Dim iframeDoc As MSHTML.HTMLDocument
Dim doc As MSHTML.HTMLDocument
Set appIE = New InternetExplorerMedium
sURL = "https://example.login.aspx"
With appIE
.Navigate sURL
.Visible = True
End With
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
Set objCollection = appIE.Document.getElementsByTagName
'Set appIE = Nothing
appIE.Document.getElementById("txtUsername").Value = "user"
appIE.Document.getElementById("txtPassword").Value = "Pass"
appIE.Document.getElementById("btnLogin").Click
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
appIE.Navigate "https://example.Search.aspx"
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
Set doc = appIE.Document
Set iframeDoc = doc.frames("EncJump").Document
iframeDoc.getElementById("txtNum").Value = "0000000"
iframeDoc.getElementById("btnSearch").Click
End Sub
excel vba excel-vba
add a comment |
up vote
0
down vote
favorite
Ok so I have my excel VBA macro longing into my site and from the landing I direct it to a search page but I'm getting This Error after IE gets to the search page. I thought resetting the objcollection on the new page would work but I don't know how to set focus or select the new page or what... I new to using VBA with IE for automation sorry if it's super obvious.
Sub GoToWebsiteTest2()
Dim appIE As InternetExplorerMedium
Dim objElement As Object
Dim objCollection As Object
Set appIE = New InternetExplorerMedium
sURL = "https://example.login.aspx"
With appIE
.Navigate sURL
.Visible = True
End With
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
Set objCollection = appIE.Document.getElementsByTagName
'Set appIE = Nothing
appIE.Document.getElementById("txtUsername").Value = "user"
appIE.Document.getElementById("txtPassword").Value = "Pass"
appIE.Document.getElementById("btnLogin").Click
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
appIE.Navigate "https://example.Search.aspx"
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
Set objCollection = appIE.Document.getElementsByTagName
*appIE.Document.getElementById("txtNum").Value = "0000000"*
appIE.Document.getElementById("btnSearch").Click
End Sub
I changed it to this and it worked great the elements were in an iframe
Sub GoToWebsiteTest2()
Dim appIE As InternetExplorerMedium
Dim objElement As Object
Dim objCollection As Object
Dim iframeDoc As MSHTML.HTMLDocument
Dim doc As MSHTML.HTMLDocument
Set appIE = New InternetExplorerMedium
sURL = "https://example.login.aspx"
With appIE
.Navigate sURL
.Visible = True
End With
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
Set objCollection = appIE.Document.getElementsByTagName
'Set appIE = Nothing
appIE.Document.getElementById("txtUsername").Value = "user"
appIE.Document.getElementById("txtPassword").Value = "Pass"
appIE.Document.getElementById("btnLogin").Click
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
appIE.Navigate "https://example.Search.aspx"
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
Set doc = appIE.Document
Set iframeDoc = doc.frames("EncJump").Document
iframeDoc.getElementById("txtNum").Value = "0000000"
iframeDoc.getElementById("btnSearch").Click
End Sub
excel vba excel-vba
On which line does the error occur? It may be that you need to wait for an element to become present, or an element resides within a frame/iframe or even in another window if you have a pop-up. Additionally, using the snippet tool via edit is good for sharing relevant HTML to aid with diagnosing any problems with element selection.
– QHarr
Nov 8 at 20:21
The one with the asterisks 3rd to the last. I assume after I nave to the new page I need to update a collection or object with the new element IDs so I can focus on them. I would provide the HTML but I can't I would probably get in trouble for posting it.
– Emein
Nov 8 at 20:28
You aren't referencing a collection on the error line. It is possible as I said above that you need to wait for the element to be present with a timed loop to prevent infinite looping, or you may need to negotiate a parent frame/iframe. If you open dev tools you can highlight the relevant element in the html and then search to see if it is contained within a parent iframe/frame tag. You don't appear to use the collection at all. If there were a problem with referencing a stale collection you would most likely get a permission denied message.
– QHarr
Nov 8 at 20:42
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Ok so I have my excel VBA macro longing into my site and from the landing I direct it to a search page but I'm getting This Error after IE gets to the search page. I thought resetting the objcollection on the new page would work but I don't know how to set focus or select the new page or what... I new to using VBA with IE for automation sorry if it's super obvious.
Sub GoToWebsiteTest2()
Dim appIE As InternetExplorerMedium
Dim objElement As Object
Dim objCollection As Object
Set appIE = New InternetExplorerMedium
sURL = "https://example.login.aspx"
With appIE
.Navigate sURL
.Visible = True
End With
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
Set objCollection = appIE.Document.getElementsByTagName
'Set appIE = Nothing
appIE.Document.getElementById("txtUsername").Value = "user"
appIE.Document.getElementById("txtPassword").Value = "Pass"
appIE.Document.getElementById("btnLogin").Click
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
appIE.Navigate "https://example.Search.aspx"
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
Set objCollection = appIE.Document.getElementsByTagName
*appIE.Document.getElementById("txtNum").Value = "0000000"*
appIE.Document.getElementById("btnSearch").Click
End Sub
I changed it to this and it worked great the elements were in an iframe
Sub GoToWebsiteTest2()
Dim appIE As InternetExplorerMedium
Dim objElement As Object
Dim objCollection As Object
Dim iframeDoc As MSHTML.HTMLDocument
Dim doc As MSHTML.HTMLDocument
Set appIE = New InternetExplorerMedium
sURL = "https://example.login.aspx"
With appIE
.Navigate sURL
.Visible = True
End With
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
Set objCollection = appIE.Document.getElementsByTagName
'Set appIE = Nothing
appIE.Document.getElementById("txtUsername").Value = "user"
appIE.Document.getElementById("txtPassword").Value = "Pass"
appIE.Document.getElementById("btnLogin").Click
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
appIE.Navigate "https://example.Search.aspx"
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
Set doc = appIE.Document
Set iframeDoc = doc.frames("EncJump").Document
iframeDoc.getElementById("txtNum").Value = "0000000"
iframeDoc.getElementById("btnSearch").Click
End Sub
excel vba excel-vba
Ok so I have my excel VBA macro longing into my site and from the landing I direct it to a search page but I'm getting This Error after IE gets to the search page. I thought resetting the objcollection on the new page would work but I don't know how to set focus or select the new page or what... I new to using VBA with IE for automation sorry if it's super obvious.
Sub GoToWebsiteTest2()
Dim appIE As InternetExplorerMedium
Dim objElement As Object
Dim objCollection As Object
Set appIE = New InternetExplorerMedium
sURL = "https://example.login.aspx"
With appIE
.Navigate sURL
.Visible = True
End With
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
Set objCollection = appIE.Document.getElementsByTagName
'Set appIE = Nothing
appIE.Document.getElementById("txtUsername").Value = "user"
appIE.Document.getElementById("txtPassword").Value = "Pass"
appIE.Document.getElementById("btnLogin").Click
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
appIE.Navigate "https://example.Search.aspx"
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
Set objCollection = appIE.Document.getElementsByTagName
*appIE.Document.getElementById("txtNum").Value = "0000000"*
appIE.Document.getElementById("btnSearch").Click
End Sub
I changed it to this and it worked great the elements were in an iframe
Sub GoToWebsiteTest2()
Dim appIE As InternetExplorerMedium
Dim objElement As Object
Dim objCollection As Object
Dim iframeDoc As MSHTML.HTMLDocument
Dim doc As MSHTML.HTMLDocument
Set appIE = New InternetExplorerMedium
sURL = "https://example.login.aspx"
With appIE
.Navigate sURL
.Visible = True
End With
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
Set objCollection = appIE.Document.getElementsByTagName
'Set appIE = Nothing
appIE.Document.getElementById("txtUsername").Value = "user"
appIE.Document.getElementById("txtPassword").Value = "Pass"
appIE.Document.getElementById("btnLogin").Click
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
appIE.Navigate "https://example.Search.aspx"
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
Set doc = appIE.Document
Set iframeDoc = doc.frames("EncJump").Document
iframeDoc.getElementById("txtNum").Value = "0000000"
iframeDoc.getElementById("btnSearch").Click
End Sub
excel vba excel-vba
excel vba excel-vba
edited Nov 9 at 15:40
asked Nov 8 at 20:18
Emein
32
32
On which line does the error occur? It may be that you need to wait for an element to become present, or an element resides within a frame/iframe or even in another window if you have a pop-up. Additionally, using the snippet tool via edit is good for sharing relevant HTML to aid with diagnosing any problems with element selection.
– QHarr
Nov 8 at 20:21
The one with the asterisks 3rd to the last. I assume after I nave to the new page I need to update a collection or object with the new element IDs so I can focus on them. I would provide the HTML but I can't I would probably get in trouble for posting it.
– Emein
Nov 8 at 20:28
You aren't referencing a collection on the error line. It is possible as I said above that you need to wait for the element to be present with a timed loop to prevent infinite looping, or you may need to negotiate a parent frame/iframe. If you open dev tools you can highlight the relevant element in the html and then search to see if it is contained within a parent iframe/frame tag. You don't appear to use the collection at all. If there were a problem with referencing a stale collection you would most likely get a permission denied message.
– QHarr
Nov 8 at 20:42
add a comment |
On which line does the error occur? It may be that you need to wait for an element to become present, or an element resides within a frame/iframe or even in another window if you have a pop-up. Additionally, using the snippet tool via edit is good for sharing relevant HTML to aid with diagnosing any problems with element selection.
– QHarr
Nov 8 at 20:21
The one with the asterisks 3rd to the last. I assume after I nave to the new page I need to update a collection or object with the new element IDs so I can focus on them. I would provide the HTML but I can't I would probably get in trouble for posting it.
– Emein
Nov 8 at 20:28
You aren't referencing a collection on the error line. It is possible as I said above that you need to wait for the element to be present with a timed loop to prevent infinite looping, or you may need to negotiate a parent frame/iframe. If you open dev tools you can highlight the relevant element in the html and then search to see if it is contained within a parent iframe/frame tag. You don't appear to use the collection at all. If there were a problem with referencing a stale collection you would most likely get a permission denied message.
– QHarr
Nov 8 at 20:42
On which line does the error occur? It may be that you need to wait for an element to become present, or an element resides within a frame/iframe or even in another window if you have a pop-up. Additionally, using the snippet tool via edit is good for sharing relevant HTML to aid with diagnosing any problems with element selection.
– QHarr
Nov 8 at 20:21
On which line does the error occur? It may be that you need to wait for an element to become present, or an element resides within a frame/iframe or even in another window if you have a pop-up. Additionally, using the snippet tool via edit is good for sharing relevant HTML to aid with diagnosing any problems with element selection.
– QHarr
Nov 8 at 20:21
The one with the asterisks 3rd to the last. I assume after I nave to the new page I need to update a collection or object with the new element IDs so I can focus on them. I would provide the HTML but I can't I would probably get in trouble for posting it.
– Emein
Nov 8 at 20:28
The one with the asterisks 3rd to the last. I assume after I nave to the new page I need to update a collection or object with the new element IDs so I can focus on them. I would provide the HTML but I can't I would probably get in trouble for posting it.
– Emein
Nov 8 at 20:28
You aren't referencing a collection on the error line. It is possible as I said above that you need to wait for the element to be present with a timed loop to prevent infinite looping, or you may need to negotiate a parent frame/iframe. If you open dev tools you can highlight the relevant element in the html and then search to see if it is contained within a parent iframe/frame tag. You don't appear to use the collection at all. If there were a problem with referencing a stale collection you would most likely get a permission denied message.
– QHarr
Nov 8 at 20:42
You aren't referencing a collection on the error line. It is possible as I said above that you need to wait for the element to be present with a timed loop to prevent infinite looping, or you may need to negotiate a parent frame/iframe. If you open dev tools you can highlight the relevant element in the html and then search to see if it is contained within a parent iframe/frame tag. You don't appear to use the collection at all. If there were a problem with referencing a stale collection you would most likely get a permission denied message.
– QHarr
Nov 8 at 20:42
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Since you are unable to post the HTML, this is more speculation than anything. There are 2 likely issues:
- Your issue is related to an iframe - which if this is the case there's not much we can do without seeing the HTML.
- Your issue is that your element hasn't fully loaded (yes, happens even if readystate = complete).
So Change the line giving you issues to:
dim startTime as single
starttime = timer
on error resume next
do while appIE.Document.getElementById("txtNum") is nothing
if timer - starttime > 10 then 'Change 10 to # of max seconds to wait
msgbox "Element didn't load! Check internet connection, aborting"
exit sub
else
doevents
end if
loop
on error goto 0
appIE.Document.getElementById("txtNum").Value = "0000000"
To build on point # 1 - You can think of an iFrame as it's own document. Usually you will see a the tagname <iframe>
. You will need to use that object's document (I usually set it equal to iframe.contentdocument
) and then proceed as normal.
1
Good point. Just addedexit sub
instead ofis not
. Thanks @QHarr
– K.Dᴀᴠɪs
Nov 8 at 20:49
You were 100% right it was an iframe. I got it working and added the changes after my original post
– Emein
Nov 8 at 22:22
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Since you are unable to post the HTML, this is more speculation than anything. There are 2 likely issues:
- Your issue is related to an iframe - which if this is the case there's not much we can do without seeing the HTML.
- Your issue is that your element hasn't fully loaded (yes, happens even if readystate = complete).
So Change the line giving you issues to:
dim startTime as single
starttime = timer
on error resume next
do while appIE.Document.getElementById("txtNum") is nothing
if timer - starttime > 10 then 'Change 10 to # of max seconds to wait
msgbox "Element didn't load! Check internet connection, aborting"
exit sub
else
doevents
end if
loop
on error goto 0
appIE.Document.getElementById("txtNum").Value = "0000000"
To build on point # 1 - You can think of an iFrame as it's own document. Usually you will see a the tagname <iframe>
. You will need to use that object's document (I usually set it equal to iframe.contentdocument
) and then proceed as normal.
1
Good point. Just addedexit sub
instead ofis not
. Thanks @QHarr
– K.Dᴀᴠɪs
Nov 8 at 20:49
You were 100% right it was an iframe. I got it working and added the changes after my original post
– Emein
Nov 8 at 22:22
add a comment |
up vote
1
down vote
accepted
Since you are unable to post the HTML, this is more speculation than anything. There are 2 likely issues:
- Your issue is related to an iframe - which if this is the case there's not much we can do without seeing the HTML.
- Your issue is that your element hasn't fully loaded (yes, happens even if readystate = complete).
So Change the line giving you issues to:
dim startTime as single
starttime = timer
on error resume next
do while appIE.Document.getElementById("txtNum") is nothing
if timer - starttime > 10 then 'Change 10 to # of max seconds to wait
msgbox "Element didn't load! Check internet connection, aborting"
exit sub
else
doevents
end if
loop
on error goto 0
appIE.Document.getElementById("txtNum").Value = "0000000"
To build on point # 1 - You can think of an iFrame as it's own document. Usually you will see a the tagname <iframe>
. You will need to use that object's document (I usually set it equal to iframe.contentdocument
) and then proceed as normal.
1
Good point. Just addedexit sub
instead ofis not
. Thanks @QHarr
– K.Dᴀᴠɪs
Nov 8 at 20:49
You were 100% right it was an iframe. I got it working and added the changes after my original post
– Emein
Nov 8 at 22:22
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Since you are unable to post the HTML, this is more speculation than anything. There are 2 likely issues:
- Your issue is related to an iframe - which if this is the case there's not much we can do without seeing the HTML.
- Your issue is that your element hasn't fully loaded (yes, happens even if readystate = complete).
So Change the line giving you issues to:
dim startTime as single
starttime = timer
on error resume next
do while appIE.Document.getElementById("txtNum") is nothing
if timer - starttime > 10 then 'Change 10 to # of max seconds to wait
msgbox "Element didn't load! Check internet connection, aborting"
exit sub
else
doevents
end if
loop
on error goto 0
appIE.Document.getElementById("txtNum").Value = "0000000"
To build on point # 1 - You can think of an iFrame as it's own document. Usually you will see a the tagname <iframe>
. You will need to use that object's document (I usually set it equal to iframe.contentdocument
) and then proceed as normal.
Since you are unable to post the HTML, this is more speculation than anything. There are 2 likely issues:
- Your issue is related to an iframe - which if this is the case there's not much we can do without seeing the HTML.
- Your issue is that your element hasn't fully loaded (yes, happens even if readystate = complete).
So Change the line giving you issues to:
dim startTime as single
starttime = timer
on error resume next
do while appIE.Document.getElementById("txtNum") is nothing
if timer - starttime > 10 then 'Change 10 to # of max seconds to wait
msgbox "Element didn't load! Check internet connection, aborting"
exit sub
else
doevents
end if
loop
on error goto 0
appIE.Document.getElementById("txtNum").Value = "0000000"
To build on point # 1 - You can think of an iFrame as it's own document. Usually you will see a the tagname <iframe>
. You will need to use that object's document (I usually set it equal to iframe.contentdocument
) and then proceed as normal.
edited Nov 8 at 20:54
answered Nov 8 at 20:40
K.Dᴀᴠɪs
6,484112140
6,484112140
1
Good point. Just addedexit sub
instead ofis not
. Thanks @QHarr
– K.Dᴀᴠɪs
Nov 8 at 20:49
You were 100% right it was an iframe. I got it working and added the changes after my original post
– Emein
Nov 8 at 22:22
add a comment |
1
Good point. Just addedexit sub
instead ofis not
. Thanks @QHarr
– K.Dᴀᴠɪs
Nov 8 at 20:49
You were 100% right it was an iframe. I got it working and added the changes after my original post
– Emein
Nov 8 at 22:22
1
1
Good point. Just added
exit sub
instead of is not
. Thanks @QHarr– K.Dᴀᴠɪs
Nov 8 at 20:49
Good point. Just added
exit sub
instead of is not
. Thanks @QHarr– K.Dᴀᴠɪs
Nov 8 at 20:49
You were 100% right it was an iframe. I got it working and added the changes after my original post
– Emein
Nov 8 at 22:22
You were 100% right it was an iframe. I got it working and added the changes after my original post
– Emein
Nov 8 at 22:22
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53215523%2fvba-i-cant-interact-with-the-elements-on-the-next-page-after-i-log-in%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
On which line does the error occur? It may be that you need to wait for an element to become present, or an element resides within a frame/iframe or even in another window if you have a pop-up. Additionally, using the snippet tool via edit is good for sharing relevant HTML to aid with diagnosing any problems with element selection.
– QHarr
Nov 8 at 20:21
The one with the asterisks 3rd to the last. I assume after I nave to the new page I need to update a collection or object with the new element IDs so I can focus on them. I would provide the HTML but I can't I would probably get in trouble for posting it.
– Emein
Nov 8 at 20:28
You aren't referencing a collection on the error line. It is possible as I said above that you need to wait for the element to be present with a timed loop to prevent infinite looping, or you may need to negotiate a parent frame/iframe. If you open dev tools you can highlight the relevant element in the html and then search to see if it is contained within a parent iframe/frame tag. You don't appear to use the collection at all. If there were a problem with referencing a stale collection you would most likely get a permission denied message.
– QHarr
Nov 8 at 20:42