1

As a newbie writing Macro to automate Chrome (v 75.0.3770.100) using Selenium Basic ChromeDriver (v 75.0.3770.140) in Excel (2013) VBE, I'm trying to find a way to click a button. The id keeps changing. Here's the HTML:

<td align="left">
<button type="submit" id="nHuPf" class="login_btn y-btn-primary z-button">Login</button>
</td>

I've tried this to no avail:

obj.FindElementByClass("login_btn y-btn-primary z-button").Click

' The macro starts with this:

Dim obj As New ChromeDriver

obj.Start "chrome", "   "
obj.Get "https://sh.com/backoffice"

Would appreciate any advice on how to click this button using the Selenium Type Library in Excel VBE, thanks.

QHarr
  • 83,427
  • 12
  • 54
  • 101
DWP
  • 105
  • 1
  • 11

2 Answers2

2

Try javascript to execute

obj.ExecuteScript "document.querySelector('.login_btn').click();"
QHarr
  • 83,427
  • 12
  • 54
  • 101
1

To click on the element with text as Login you can use either of the following Locator Strategies:

  • cssSelector:

    driver.FindElementByCss("button.login_btn.y-btn-primary.z-button[type='submit']").Click
    
  • xpath:

    driver.FindElementByXPath("//button[@class='login_btn y-btn-primary z-button' and text()='Login']").Click
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352