0

I am trying to write an applescript application that logs into a website upon launching. So far I can successfully open Chrome, load the web page into the active tab, select and input the password, but I cannot click the submit button.

Below is the element on the page:

<button type="submit" class="btn  btn--ac" alt="Login" 
   title="Login" tabindex="6"><i aria-hidden="true" 
   class="lush  lush-locked"></i> Login</button>

My skill level in javascript is little to none, yet I cannot find a way to successfully select this item and click it. I have tried already using the TagName and ClassName but it does not work, perhaps my syntax is incorrect. Is there a way to do this without a ID type?

I have tried:

execute front window's active tab javascript 
"document.getElementByClassName('btn, btn--ac').click()"

execute front window's active tab javascript 
"document.getElementByTagName('button').click()"

I should note this script runs in Google Chrome.

Thanks for any help in advance.

2
  • Is it the only button with that class? Or the first? You can try something like $('.btn--ac').first().click(). Commented Sep 14, 2015 at 20:25
  • It is the only button on the whole page and the only element with the btn and btn--ac class as well Commented Sep 14, 2015 at 20:26

2 Answers 2

2

First of all you're using a wrong function. It should be

document.getElementsByClassName

Try using: (Assuming the Submit button is the only button with class btn)

document.getElementsByClassName('btn')[0].click();

Here's basic definition of the function from Mozilla:

document.getElementsByClassName():
Returns an array-like object of all child elements which have all of the given class names.

Hence, you get a list of elements. Hence, you select the first element in it (using the 0 as index), and then click on it.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Sarath, that was the problem! Works just as expected now!
0

The correct syntax in plain js to select an element by his class is:

document.getElementsByClassName('btn--ac');

With this you'll get an array with all elements with the class 'btw--ac'. In your case try this:

document.getElementsByClassName('btn--ac')[0].click();

Comments

Your Answer

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