Vba Selenium problem - can't control popup/popover

Js Smith

Board Regular
Joined
Jul 24, 2020
Messages
51
Office Version
  1. 2010
Platform
  1. Windows
Hi guys!
I'm trying to automate some account creations using selenium chromedriver. I have everything but the popup (popover?).
I can't see is anywhere using Inspect and when I check it with the IDE recorder, it doesn't have any class, id, xpath, etc.
Attached is a screenshot of the irritant and what the IDE recorder shows when I use it while clicking in the field, entering "Test" then clicking ok.

The website is highly secured and belongs to our vendor so I can't give you all the code from the page. Hopefully this is enough data. Here's my macro so far:

VBA Code:
Sub MarkedAsVerified()

Dim bot As New ChromeDriver, Assert As New Assert

sUID = InputBox("Enter your username")
sPWD = InputBox("Enter your password")


 bot.Get "https://qa.com/account/user/login"


 bot.FindElementByCss("input[name=j_username]").SendKeys sUID
 bot.FindElementByCss("input[name=j_password]").SendKeys sPWD
 bot.FindElementByCss("input[type=submit]").Click
 
Application.Wait (Now + TimeValue("0:00:03"))

 With Worksheets("Data2")
    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    Set rng1 = .Range("K2:K" & LastRow)

For Z = 2 To LastRow

    bot.FindElementByCss("[href='/hix/crm/member/managemembers']").Click
    bot.FindElementByLinkText("Manage Members").Click
    bot.FindElementByCss("input[name=firstName]").SendKeys Worksheets("Data2").Range("A" & Z).Value
    bot.FindElementByCss("input[name=lastName]").SendKeys Worksheets("Data2").Range("B" & Z).Value
    bot.SendKeys bot.keys.Enter

    bot.FindElementByLinkText(Worksheets("Data2").Range("C" & Z).Value).Click
    

     
On Error Resume Next

    bot.FindElementById("mark_verified").Click

'  Need to enter "Test" then click OK on the popup/popover

'    bot.SwitchToAlert.Accept                      <<-------  runtime 26 UnexpectedAlertOpenError
'bot.FindElementById("#container-wrap").SendKeys ("Test{Enter}")   <---------No  reaction at all

How would you overcome this problem?
Thanks, as always!
 

Attachments

  • popup_over.PNG
    popup_over.PNG
    7.8 KB · Views: 52
  • IDErecorded.PNG
    IDErecorded.PNG
    16.3 KB · Views: 57

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
The popup is displayed by the JavaScript prompt method. As such, it doesn't have an id, name or class.

Try this:
VBA Code:
    Dim JSprompt As Selenium.Alert
    Set JSprompt = driver.SwitchToAlert
    JSprompt.SendKeys "Test"
    JSprompt.Accept
Get rid of the On Error Resume Next because you want to see any errors.
 
Upvote 0
The popup is displayed by the JavaScript prompt method. As such, it doesn't have an id, name or class.

Try this:
VBA Code:
    Dim JSprompt As Selenium.Alert
    Set JSprompt = driver.SwitchToAlert
    JSprompt.SendKeys "Test"
    JSprompt.Accept
Get rid of the On Error Resume Next because you want to see any errors.

Thanks John_w!

It doesn't seem to be affecting the popup. Do I need another reference for alerts? I also noticed I erred in my edits, trying to remove sensitive data, before posting my code. I have a
VBA Code:
On Error GoTo 0
on the other side, in case the mark_verified is not present on the account. Here is my code with your suggestion added as well as attachments showing my references and showing "Test: is not sent to the popup:

VBA Code:
Sub MarkedAsVerified()

Dim bot As New ChromeDriver, Assert As New Assert

sUID = InputBox("Enter your username")
sPWD = InputBox("Enter your password")


 bot.Get "https://qa.com/account/user/login"


 bot.FindElementByCss("input[name=j_username]").SendKeys sUID
 bot.FindElementByCss("input[name=j_password]").SendKeys sPWD
 bot.FindElementByCss("input[type=submit]").Click
 
Application.Wait (Now + TimeValue("0:00:03"))

 With Worksheets("Data2")
    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    Set rng1 = .Range("K2:K" & LastRow)

For Z = 2 To LastRow

    bot.FindElementByCss("[href='/hix/crm/member/managemembers']").Click
    bot.FindElementByLinkText("Manage Members").Click
    bot.FindElementByCss("input[name=firstName]").SendKeys Worksheets("Data2").Range("A" & Z).Value
    bot.FindElementByCss("input[name=lastName]").SendKeys Worksheets("Data2").Range("B" & Z).Value
    bot.SendKeys bot.keys.Enter

    bot.FindElementByLinkText(Worksheets("Data2").Range("C" & Z).Value).Click
    

     
On Error Resume Next

    bot.FindElementById("mark_verified").Click



'  Need to enter "Test" then click OK on the popup/popover

'    bot.SwitchToAlert.Accept                      <<-------  runtime 26 UnexpectedAlertOpenError
'bot.FindElementById("#container-wrap").SendKeys ("Test{Enter}")   <---------No  reaction at all

'        Alert Alert = bot.switchTo().Alert()   <<---------------- also no reaction
'        bot.alert.accept()            <<---------------- also no reaction



    Dim JSprompt As selenium.Alert
    Set JSprompt = bot.SwitchToAlert   
    JSprompt.SendKeys "Test"
    JSprompt.Accept


On Error GoTo 0

    
Next
End With


'bot.Quit

End Sub

I did change
VBA Code:
driver.SwitchToAlert
to
VBA Code:
bot.SwitchToAlert
to get past a 424 Runtime error. Thanks for your thoughts on this!
 

Attachments

  • references.PNG
    references.PNG
    11 KB · Views: 28
  • BreakPoint.PNG
    BreakPoint.PNG
    20.5 KB · Views: 26
Upvote 0
No other references are required.

Yes, correct to change "driver" to "bot".

I have a
VBA Code:
On Error GoTo 0
on the other side, in case the mark_verified is not present on the account.

But the OERN is still active when attempting to clear the popup, so any errors will be suppressed. Move the OEG0 like this:
VBA Code:
On Error Resume Next
    bot.FindElementById("mark_verified").Click
On Error Goto 0

If you then get an error on Set JSprompt = bot.SwitchToAlert it could mean the popup (alert) doesn't exist yet, in which case specify the timeout argument:

VBA Code:
    Set JSprompt = bot.SwitchToAlert(5000)  '5 seconds
That's all I can think of.
 
Last edited:
Upvote 0
Solution
No other references are required.

Yes, correct to change "driver" to "bot".



But the OERN is still active when attempting to clear the popup, so any errors will be suppressed. Move the OEG0 like this:
VBA Code:
On Error Resume Next
    bot.FindElementById("mark_verified").Click
On Error Goto 0

If you then get an error on Set JSprompt = bot.SwitchToAlert it could mean the popup (alert) doesn't exist yet, in which case specify the timeout argument:

VBA Code:
    Set JSprompt = bot.SwitchToAlert(5000)  '5 seconds
That's all I can think of.
Thanks for pointing out the error suppression was in the wrong spot for troubleshooting. Obviously been looking at this too long! 🤪

I added the timeout, as suggested and we're in business! Thank you very much for the help. Hope you have a great week!
 
Upvote 0

Forum statistics

Threads
1,223,950
Messages
6,175,582
Members
452,653
Latest member
craigje92

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