Search code examples
vbaseleniumselenium-webdriverselenium-chromedriver

VBA button not clicking - element not visible error


I'm trying to click a button using a VBA Chrome driver via Selenium but I get an ElementNotVisibleError

The HTML code for the button is -

<button class="base-button" id="primary-button" classnames="primary-button" title="Continue">Continue</button>

I've tried to check the element exists and VBA returns TRUE for the following -

MyBrowser.IsElementPresent(Findby.ID("primary-button"))

but when I try to click the button using the following code, i get the error -

MyBrowser.FindElementById("primary-button").Click

Solution

  • To click on the element you can use either of the following locator strategies:

    • Using FindElementByCss:

      MyBrowser.FindElementByCss("button.base-button#primary-button[title='Continue']").Click
      
    • Using FindElementByXPath:

      MyBrowser.FindElementByXPath("//button[@class='base-button' and @id='primary-button'][@title='Continue' and text()='Continue']").Click