Cannot Login with VBA + Selenium

bunburyst

New Member
Joined
Apr 18, 2018
Messages
24
Currently I have used selenium webdriver to login to a website and send text with VBA macro. The problem is that since a few days the code dont work. I think the web code have changed. I have been checking the code of the web page but I can't find the correct one.

Any help is appreciated.

Selenium basic 2.0 Windows 10 Excel 2010 Edge browser

VBA Code:
Sub Repsol()

Dim driver As New WebDriver
Set driver = New EdgeDriver
With driver

.Start "edge"
.Get "https://login.repsol.com/es/Landing/AuthnPage?returnUrl=https://www.repsol.com/es_es/"

 With .FindElementByClass("gigya-login-form")

    .FindElementByClass("gigya-input-text").SendKeys "user" 'your user
    .FindElementByClass("gigya-input-password").SendKeys "password" 'your password
    
    
     .FindElementByClass("gigya-input-submit").submit
End With

Application.Wait Now + TimeSerial(0, 0, 10)

.Get "https://www.repsol.com/es_es/aplicaciones/SO/WebEESS/default.aspx?usuario="""
Application.Wait Now + TimeSerial(0, 0, 10)

    
.Get "https://www.repsol.com/SO/WebEESS/Pages/Carburantes/PeticionCarburante/Peticion.aspx"

With .FindElementByClass("tablaContenedora")

    .FindElementById("ctl00_zona1_grdwCarburantes_ctl02_lbltxtCantidad").SendKeys [B7]

     End With
End With

End Sub
 

Attachments

  • error.jpg
    error.jpg
    17.4 KB · Views: 35

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I seem the page declare it's available much before it is really there.
Try adding this block in this position:
VBA Code:
'other instructions
.Start "edge"
.Get "https://login.repsol.com/es/Landing/AuthnPage?returnUrl=https://www.repsol.com/es_es/"
'>>>>> ADD THIS BLOCK:
On Error Resume Next
    For I = 1 To 15
        Set GIGYA = .FindElementByClass("gigya-login-form")
        If GIGYA Is Nothing Then
            Debug.Print I, TypeName(GIGYA)
            Application.Wait Now + TimeSerial(0, 0, 1)
        Else
            Exit For
        End If
    Next I
On Error GoTo 0
Debug.Print I, TypeName(GIGYA)
If I > 15 Then
    MsgBox ("Impossible to login, aborted")
    Exit Sub
End If
'<<< END OF BLOCK
 With .FindElementByClass("gigya-login-form")
'continue...
In this way you add additional waits, up to 15 seconds, for the page really available

Also add Dim GIGYA As Object on the declaration area
Try...
 
Upvote 0
Solution
I seem the page declare it's available much before it is really there.
Try adding this block in this position:

Now it works. Thanks a lot. The problem is that, the code did not wait for the "form" to be loaded.
Another thing, i have a doubt about what code I can use to wait for the web to be loaded.

Thanks Antonio.
 
Upvote 0
Another thing, i have a doubt about what code I can use to wait for the web to be loaded
You don't like the method I used?
Theory says that Selenium commands waits by themselves the end of the operations, but this is quite difficult to guarantee with script based pages (99% of the pages, nowadays).

Thus the metod is search for something that should be there and wait until it is there.

It was the "form" in your case; very often it is a long long table to be completed; in other cases it could ...depend on the page.

Bye
 
Upvote 0
You don't like the method I used?
Theory says that Selenium commands waits by themselves the end of the operations, but this is quite difficult to guarantee with script based pages (99% of the pages, nowadays).

Thus the metod is search for something that should be there and wait until it is there.

It was the "form" in your case; very often it is a long long table to be completed; in other cases it could ...depend on the page.

Bye
Sorry Antonio, I think I didn't explain myself well. Your code works perfectly, I really appreciate your help.
I was referring to the following commands in my code, where I am using Application.Wait Now, I don't know if there is another way to wait for those other web.

VBA Code:
.Get "https://www.repsol.com/es_es/aplicaciones/SO/WebEESS/default.aspx?usuario="""
Application.Wait Now + TimeSerial(0, 0, 10)

Thank you so much.
 
Upvote 0
Try the same approach I used:
VBA Code:
On Error Resume Next
Set ObjectVariable = Nothing
For I=1 to 20        'How much max wait?
  Set ObjectVariable = The Item you look for
  If ObjectVariable is nothing then
      wait 1 second
  else
     exit for
  End if
next I
On Error Goto 0
In this way you will wait only the time it is necessary

Bye
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,638
Members
449,093
Latest member
Ahmad123098

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