![]() |
GUI Scripting question
I'm trying to have Applescript enter a user name and password into a popup window that appears when I want to open my router's administration window. Using Accessibility Inspector, I find the following attributes on the user name text field:
Quote:
Code:
tell application "System Events" |
This may work
Code:
activate application "Safari""Keychain Scripting" Code:
tell application "Safari" to activate |
Thanks, now I'm getting somewhere. I can get it to click through to the main router admin page using the following code. However, still not quite getting how to figure out which button to press on the next page. AI gives me the following attributes:
Quote:
Code:
activate application "Safari"Quote:
|
Its a little hard for me to work out your elements.
You could try Code:
click radio button 1 of group 1 of UI element 1 of scroll area 1 of group 1 of window 1Code:
set RBs to radio buttons of UI element 1 of UI element 1 of UI element 1 of UI element 1 of window 1 |
Hm... replacing "web area 1" with "UI element 1" at least gets it to compile, but running either that script or your other suggestion gets me the
Quote:
So is AI not giving enough information to figure out what code to pass to System Events? FWIW, I'm trying to click on the radio button that disables the wireless access point. What more information do I need to figure this out? |
that error just means that it's not finding the specified UI element at the location specified. almost invariably it means that you've gotten something mixed up (used 'group 1' where you should have used 'group 2', or something like that). trial and error is the only way to parse it that I know of.
|
This is turning out to be a lot harder than I thought.... Question: using the DOM Inspector in Firefox, the structure of the button's place in the page is shown as:
Quote:
|
download UIElementInspector and play with it. it's a good tool, which should give you the info you need. and no, the DOM structure of the HTML document probably won't help (it's not how it renders in the browser, but how the browser renders it in the GUI).
if you want to switch to Safari, you can write javascript into an applescript, which may make the task easier. I don't know if you can do that in Firefox. |
Hey tw, thanks for the suggestions. I actually did download UIElementInspector and pasted the results into my second post above. Unfortunately, neither I nor Mark Hunte were able to figure out exactly which element to pass to System Events from that info. Did you take a look at that?
There oughta be a tool that you could use to drag and drop GUI elements into a script editor... |
whats the name of the button.
put is name where the "radio button" is in this script and see if that works. I tried this on a web page, and it worked fine for me. But I know the name of the button. Code:
tell application "Safari" |
I was just trying this... not quite there yet. The name of the radio button group is "wirelessStatus" and the button I want to click is named "Disable":
Quote:
Code:
tell application "Safari"Also, the form name is "F1"... tried writing Code:
tell application "Safari"Code:
do JavaScript "document.getElementByID('F1.wirelessStatus')[1].click()"Code:
do JavaScript "document.getElementByID('F1.wirelessStatus[1]').click()"Code:
do JavaScript "document.getElementByID('F1.wirelessStatus[1]').checked = true"Code:
do JavaScript "document.getElementByID('F1.wirelessStatus')[1].checked = true" |
It seems far simpler to work out the process that your browser actually uses to login to the router - and emulate that process.
What happens when you type into your browser? Code:
http://username:password@RouterIPNumber |
Ok I only know javascript by putting things together from real javascript examples..
And I think my first script will only work on buttons, not radio buttons. So.. I have now got more than one radio button on different pages to be set. And was coming back here to ask you the form name, and realise you where already trying to do, what I have done. So I do not need to explain to much. Try Code:
do JavaScript "document.F1.wirelessStatus[1].checked=true" in document 1F1 = the form name wirelessStatus = the radio button/s group name [1] radio button number in group -- Remember that the group is an array so it starts from 0 onwards checked=true = set checked, uncheck would be . checked=false Now I am just trying to figure out a way to do it by value. I can find the values no problem, just want them selected by it. |
To add to my last post,
Get radio button by its value, and check it. Code:
tell application "Safari" |
Quote:
|
Quote:
|
Quote:
Also do you know what you do if you have none alphanumeric characters in the password or user name, that would be interpreted by the browser wrong? |
Quote:
Don't focus on the specifics and ignore my general point. There are several authentication methods mentioned in the http protocol - I've just mentioned the one all routers that I've ever dealt used. It stands to reason that one of the methods mentioned in the protocol is in use in this situation. Identify the method in use - it has to be discernable from the source code of the webpage. Gotta be better and more reliable than screen scraping i.e GUI scripting. |
Quote:
Are you able to zip up a copy of the html (take out any thing you should keep secure ) and post it. That way I can look at the actual tags myself. |
Just put,
Code:
<form name="F1">Code:
do JavaScript "document.F1.wirelessStatus[0].checked=true" in document 1But a copy of the page would help to see whats really going on.. |
Quote:
Quote:
|
1 Attachment(s)
Quote:
|
You need to enclose it with the tell block.. :)
Code:
tell application "Safari" |
A Toggle for the two button Radio button array.
It checks to see if radio button 0 is checked. If it is, a 1 will be returned. The result 1 will be used to identify the radio button 1 as the radio button that will get checked. If it is not checked, then a 0 will be returned, The result 0 will be used to identify the radio button 0 as the radio button that will get checked. This is a simple toggle to check R. Buttons zero or one. Code:
tell application "Safari" |
Solved! Syntax error, of course, on my part... I was placing the last quotation mark at the end of the line instead of before "in document 1". Final code is short and sweet:
Code:
activate application "Safari"Now I just have to learn how to force Safari to quit after running this... |
tell application Safari
quit end tell |
Quote:
|
Quote:
|
Your welcome, :):)
|
Quote:
sorry for my lack of etiquette - and hey, how'd I get upgraded to a Triple-A player? |
| All times are GMT -5. The time now is 06:09 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.