Clicking a button with javascript in KBM?

Trying to click a button with the execute javascript action.

Here's the source code

<div id="ember44" class="ember-view">
Google enables the world to find, form, a…
<button class="button--unstyled link-without-visited-state inline-block font-size-inherit topcard-see-more-link" type="button">See all</button>
</div>

I see document.getElementbyID seems to be the most common method but not experienced with Javascript and not sure how to implement it

1 Like

Using the HTML element ID will work provided it stays constant. Unfortunately Google, and many others, now use a dynamic ID that changes with every time the page is displayed. So, in that case, you can't use the ID.

Using the Element Class will often work, as those don't usually change, but may not be unique to any specific element. Assuming the class of the button you want to click is either unique, or is the first used in the page, this should work:

document.querySelector('button.button--unstyled.link-without-visited-state.inline-block.font-size-inherit.topcard-see-more-link').click()

Put that script in a Execute a JavaScript in Front Browser action.

Without seeing more of the HTML code of the page, I can't test or guarantee this will work.

Let us know if this works for your, or you have further questions.

3 Likes

Thanks works perfect, seems to work on multiple pages so far

1 Like