Skip to content Skip to sidebar Skip to footer

Powershell: How To Press A Button On A Web Page If You Don't Know The Button Id

I'm trying to fill in my username and password on a certain web page and then the press the 'sign-in' button, all automatically via Powershell. The problem is that I cannot find th

Solution 1:

I came here looking for a similar answer and figured out how to get this done. Posting here for any future searchers. As noted by Szymon, getElementsByClassName returns an array, and you will need to select the item you need before the click. In my case the classname was button and I was able to click it using the following:

$submitButton = $doc.documentElement.getElementsByClassName('button') | Select-Object -First 1$submitButton.click() 

This works for me because there is only the one item with the classname button, so your results my vary if you have more than one with the same name. Just change what you grab using select-object if need be.

Solution 2:

As @Jamie-Taylor mentioned the login button is in fact a button.

You can access it not only by the id but also by the class name using document.documentElement.getElementsByClassName. Please notice this function will return list of elements as more than one element on page can have the same class.

EDIT I was wrong: in order to have getElementsByClassName you have to call it on document.documentElement instead of document

Post a Comment for "Powershell: How To Press A Button On A Web Page If You Don't Know The Button Id"