1

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
3
  • IsElementPresent is not the same as IsElementVisible. Have you tried the latter? Further, i assume the element IS actually visible in the browser, to yourself? Commented Jul 25, 2022 at 4:32
  • You could try another way to access it, by finding it by xPath. Commented Jul 25, 2022 at 11:49
  • @C.Peck I'm unsure how to check if the element is visible in VBA, IsElementVisible isn't a command. The element is visible to myself in the browser. Commented Jul 25, 2022 at 20:02

2 Answers 2

1

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
    
Sign up to request clarification or add additional context in comments.

Comments

0

The solution I use which seems to work in all cases:

driver.ExecuteScript "arguments[0].click();", driver.FindElementByXPath("//div[@id='search-engine']/div/div/div[2]") 

Of course, you can use findelementbywhatever...

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.