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.

3
  • is there an error message? Commented Jul 15, 2019 at 3:39
  • I can see id="nHuPf" >> so why didn't you try FindElementByID? Commented Jul 15, 2019 at 3:45
  • the id changes every time the page loads Commented Jul 15, 2019 at 7:37

2 Answers 2

2

Try javascript to execute

obj.ExecuteScript "document.querySelector('.login_btn').click();"
Sign up to request clarification or add additional context in comments.

Comments

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
    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.