4

I've written the following code to open a webpage in Chrome (note, you may have to click through a "Captcha" robot test page). I can successfully enter my username and password, but I am unable to click the yellow Log in button.

Sub Annuity_Value_Selenium()
' Note: added reference to Selenium Type Library

Dim WDriver As New WebDriver
    
' Open Chrome and navigate to login page
    WDriver.Start "Chrome", ""
    WDriver.Get "https://www.prudential.com/login/"
 
' Maximize the window
    WDriver.Window.Maximize
    Application.Wait (Now + TimeValue("0:00:02"))
      
    WDriver.Get "https://www.prudential.com/login/"
    Application.Wait (Now + TimeValue("0:00:02"))
    
' log-in   
    WDriver.FindElementById("user").SendKeys ("abcd")
    WDriver.FindElementById("password").SendKeys ("efgh")

    WDriver.FindElementById("loginLink").Click
'
    Do stuff
'
End sub

I have tried the following additional approaches as well, but I am still unsuccessful in clicking the Log in button:

WDriver.FindElementByCss("a[class='btn evo-button   ']").Click

and

WDriver.FindElementByXPath("//a[contains(text(), 'Log in')]").click

I know that the webpage is loaded and active because the macro correctly inserts the username and password.

Even without using a username or password, you'll know that you were successful in clicking the button if you get an error message back saying Error: Please provide a username. How can I programmatically click the Log in button?

ron
  • 1,456
  • 3
  • 18
  • 27
  • 1
    Have you made sure the web page has enough time to load? Maybe play around with `TimeValue("0:00:10")`, etc.? Typically I use `DoEvents` with my web scraping, but I don't know how that works with Selenium. – dwirony May 09 '23 at 16:33
  • @dwirony Yes, I've tested it, it has adequate time to load. Thanks for the thought. – ron May 09 '23 at 16:47

2 Answers2

1

we.FindElementByXPath("//evo-link-button[@type='secondary']").Click

This might work for you. It gives me the following error message -

Run-time error 11

ElementNotVisibleError

element not interactable

The error message suggests that the XPath is valid and has found the element that I am aiming for but will not click it until other conditions are met, for example a valid username has been entered which I don't have.

user10186832
  • 423
  • 1
  • 9
  • 17
  • Thanks for trying, but it doesn't work. You shouldn't get any error messages other than on the web page where it should say Error: Please provide a username and Error: Please provide a password right below those two input boxes after a successful click. – ron May 10 '23 at 14:52
0

Granted, I don't have experience with Selenium WebDriver specifically in VBA and was a bit surprised to find that it doesn't support explicit waits where you can specify a condition (an element to be clickable or visible, etc...) before proceeding with an action. The usages of Explicit Wait are documented here. Perhaps the long term solution is to move to a supported language in WebDriver. However based on this stackoverflow discussion the author of SeleniumBasic did enhance find method with an implicit timeout, maybe it's worth a try...

WDriver.FindElementByCss("a[class='btn evo-button   ']", timeout:=10000).Click
yffu
  • 31
  • 4
  • as I mentioned above, I don't think it's a "wait" problem. The macro successfully enters my username and pw, it just cant click the Log in button. I'm guessing that I'm just not clicking on the right line of html. – ron May 09 '23 at 19:10