Help Figuring Out How to Click a Link

Hi. I've got a link I'm trying to click in Safari (could use Chrome if necessary) that I can't figure out. The xpath changes every time the page reloads, so I am stumped on how to proceed.

Here's a picture of the site:

Thanks for the help!

-Erik

Hey Erik

Put this in an Execute a JavaScript in Front Browser action, and give it a try.

document.querySelector('button.btn.btn-secondary').click()

Note – That action only works in Safari and Google Chrome.

-Chris

Hi Chris. Thanks for the quick reply. I tried this in both Safari and Chrome but in neither case does it start the download. Any other ideas or need me to screenshot anything different?

Thanks for your help. -Erik

I've done a bit more research (I'm mostly just guessing and hoping I get lucky). I'm using the Chrome console and I type in that javascript you've provided and it points at a different spot on the page that has this tag: "button.btn.pull-xs-left.m-r-1.btn-secondary" (which hides/shows a menu).

So I think we're close. I just need a way to get to the specific button.btn.btn-secondary that I do care about. I wish I knew javascript!

Thanks,
Erik

You need to post either the page URL (preferred), or a large block of the HTML code that is above (but includes) your desired button, so we can identify the querySelector path that uniquely finds your button.

Having taken a better look at your image, this might work:

document.querySelector('div.resettable.mdl-right+form.resettable.mdl-right button.btn.btn-secondary').click();

If that doesn't work, try this:
document.querySelector('form.resettable.mdl-right button.btn.btn-secondary').click();

Let us know if that works for you, or you have questions.

Thanks for the additional help. Those two options didn't get us there. I'm attaching the whole page with a dropbox link so you can see it. I'd give you the URL but it's behind a login, so you wouldn't be able to get to it.

-Erik

When I try to open the webarchive in Safari, I get this flashing error:

image

Does it open for you?

It did before...but now it's causing trouble. Here's a screenshot:

Hopefully it provides enough...

-Erik

It helps, but it's not really enough. We need the actual HTML code to test.
Maybe you can just save the page as HTML text, and post in a zip file.

https://www.dropbox.com/s/n40mj1gk5kvyx6e/click%20link%20help.rtf?dl=1

Here it is.

Hey Erik,

Give this a try:

document.querySelector('form button.btn.btn-secondary').click()

-Chris

2 Likes

This did it...thank you!

So now I want to try to learn a little. Can I get you to tell me why it worked?

Thanks -Erik

That worked in this case because the button of interest is in the FIRST "form" element that was found. To be more reliable, it is best to specify the class of the "form" element like this:

document.querySelector('form.dataformatselector.m-a-1 button.btn.btn-secondary').click()

assuming I have chosen the correct "form" here:

The problem with my first post:

is that I misread the class name.

The JavaScript querySelector(css_to_find) function will find the FIRST element which matches the CSS parameter.

Questions?

1 Like

This is cool. So ccstone's solution worked because this was the first form on the page. But if this button had been on a subsequent form, then we would have needed the solution that included the name of the form.

We know it's a form because of the tag and the name of the form is always called the "class"?

I'm sure it's apparent I don't have programming experience here...sorry!

Thanks!

No. Class is a specific attribute of the Form element. I circled it in the above screenshot.

To be clear, it was the first form on the page that had a button with the specified class (button.btn.btn-secondary).