Open AnkitKabra20 opened 7 years ago
Here's what I have, which works for my set up. For me the error number for alerts is 26, but maybe you need to change to 13.
On Error GoTo Handler Handler: If Err.Number = 26 Then driver.SwitchToAlert().Accept End If
I tried but it didn't work. It got stuck and doing nothing. What is your chrome version ?
Public Function Host_Test_App()
'** ' FUNCTION FOR BROWSING THE APPLICATION '** On Error Goto Handler driver.Start "chrome", "http://www.google.com" driver.Manage.DeleteAllCookies 'driver.SetCapability "unexpectedAlertBehaviour", "ignore" driver.Get "http://the-internet.herokuapp.com/javascript_alerts" driver.FindElementByCss("#content > div > ul > li:nth-child(1) > button").Click
Handler: If Err.Number = 26 Then driver.SwitchToAlert().Accept End If Resume Next
End Function
Oh sorry I also have a Continue: at the end. So:
On Error GoTo Handler Handler: If Err.Number = 26 Then driver.SwitchToAlert().Accept End If Continue:
Tried with Continue it did not work either. Its not doing any thing
Afterwards getting an error message
Hmm. Put the "On Error GoTo Handler" right above the "Handler:" line. And also add another step after the Continue: line. It can be anything, like just clicking somewhere on the page.
Tried By Putting additional line right after continue. Its doing nothing just stuck
Afterwards getting an error message
Put "On Error GoTo Handler" right above "Handler:" and right under the "....Click" line
If it's at the top like that it's not going to be called after the .Click step
Please let me know if the code should be like this
Public Function Host_Test_App()
'** ' FUNCTION FOR BROWSING THE APPLICATION '**
driver.Start "chrome", "http://www.google.com" driver.Manage.DeleteAllCookies 'driver.SetCapability "unexpectedAlertBehaviour", "ignore" driver.Get "http://the-internet.herokuapp.com/javascript_alerts"
On Error GoTo Handler Handler: driver.FindElementByCss("#content > div > ul > li:nth-child(1) > button").Click If Err.Number = 26 Or 13 Then driver.SwitchToAlert.Accept End If Continue: MsgBox driver.FindElementById("result").Attribute("innerHTML")
' Display alert
End Function
Do it this way:
Public Function Host_Test_App()
'** ' FUNCTION FOR BROWSING THE APPLICATION '**
driver.Start "chrome", "http://www.google.com" driver.Manage.DeleteAllCookies 'driver.SetCapability "unexpectedAlertBehaviour", "ignore" driver.Get "http://the-internet.herokuapp.com/javascript_alerts" driver.FindElementByCss("#content > div > ul > li:nth-child(1) > button").Click
On Error GoTo Handler Handler: If Err.Number = 26 Then driver.SwitchToAlert.Accept End If Continue: MsgBox driver.FindElementById("result").Attribute("innerHTML")
' Display alert
End Function
I did the same way you told. Its stuck and not doing any thing. and got the time out
Your missing parentheses on SwitchToAlert. I'm not sure if that matters but try this:
Public Function Host_Test_App()
'** ' FUNCTION FOR BROWSING THE APPLICATION '**
driver.Start "chrome", "http://www.google.com" driver.Manage.DeleteAllCookies 'driver.SetCapability "unexpectedAlertBehaviour", "ignore" driver.Get "http://the-internet.herokuapp.com/javascript_alerts" driver.FindElementByCss("#content > div > ul > li:nth-child(1) > button").Click
On Error GoTo Handler Handler: If Err.Number = 26 Then driver.SwitchToAlert().Accept End If Continue: MsgBox driver.FindElementById("result").Attribute("innerHTML")
' Display alert
End Function
It doesn't matter as it results the same. Are you making it done on your system. What version of chrome browser and extension you are using. May be I should look into that from that perspective.
Issue is Not with the Code but with the Chrome Driver. As from my org Stand Point Fire Fox Versions are blocked to 52.0 so I was getting the following error when launching the chrome
This Problem got fixed if I switched the for the older chromedriver version i.e 2.24 from https://chromedriver.storage.googleapis.com/index.html
Alert Issue also got resolved.
Driver.SwitchToAlert().Accept
is working now
Brother, driver.switchtoalert().accept is not working in this below scenario of sending telegram message to unsaved number.() Please help me
Hello Users,
Please help me out in getting out of this trouble. I am getting an run time error when alert appears
'On Error Resume Next driver.Start "chrome", "http://www.google.com" driver.Manage.DeleteAllCookies 'driver.Window.Maximize
driver.SetCapability "unexpectedAlertBehaviour", "ignore" driver.Get "http://the-internet.herokuapp.com/javascript_alerts" driver.FindElementByCss("#content > div > ul > li:nth-child(3) > button").Click Set dlg = driver.SwitchToAlert(Raise:=False)
Un-commenting On Error Resume Next handles the popup but alert cannot be handled.
On Error Resume Next driver.Start "chrome", "http://www.google.com" driver.SetCapability "unexpectedAlertBehaviour", "ignore" driver.Get "http://the-internet.herokuapp.com/javascript_alerts" driver.FindElementByCss("#content > div > ul > li:nth-child(3) > button").Click Set dlg = driver.SwitchToAlert(Raise:=False)
Assert.False dlg Is Nothing, "No alert present!" Assert.Equals "I am a JS Confirm", dlg.Text
' Close alert dlg.Accept
driver.SwitchToAlert.Accept