Hello here,
I'm trying to get the url in a website that requires basic auth.
I tried UI browser to get the reference, and apparently it's
static text 2 of group 1 of window 1
I just don't know how to actually get the value from that.
This is what I have:
// get app
let GoogleChrome = Application(browser);
GoogleChrome.includeStandardAdditions = true;
let window = GoogleChrome.windows[0];
let group = window.groups[1];
let url = group.texts[2];
I think it can be accomplished in applescript as well. I tried that as well, something like
tell application "Google Chrome Canary"
static text 2 of group 1 of window 1
end tell
If there's another easy way to do it, everything is welcomed!
Anyway, if somebody could help me that would be great! I want to call this script from the shell.
Hey Eduardo,
Whenever possible it's best to provide the URL to the page in question, so folks can test with the real deal.
This might work:
tell application "System Events"
tell application process "Google Chrome Canary"
set myURL to value of static text 2 of group 1 of window 1
end tell
end tell
It's generally better to scrape the page with JavaScript using the DOM, but this doesn't work in all cases – you have to experiment.
Why?
-Chris
Thanks @ccstone. It worked perfectly. This is the url i'm testing it with http://www.httpwatch.com/httpgallery/authentication/. click on the 'display image' button. I want to automate some password fills depending on the site I'm trying to access. I use lastpass but it doesn't work with basic auth, there is documentation on how to make it work but I wasn't able to enable it on chrome.
about the code you shared, I have two doubts:
- why is that we need to use "system events" instead of a direct call to Chrome?
- I have already starting coding my own automation scripts but the documentation on jxa is still little. Is it possible that you can help me?
This is what I got so far
// get app
let SystemEvents = Application("System Events");
let GoogleChrome = SystemEvents.ApplicationProcess("Google Chrome Canary");
let window = GoogleChrome.windows[0];
let group = window.groups[1];
url = window.attribute("static text 2 of group 1");
Hey Eduardo,
As far as I can see in this particular case the browser is calling an actual system dialog with secure entry fields, so we've stepped out of the browser and into the system UI.
Blame Apple and complain to them (file feedback).
I don't use JXA much for that reason, although I've been wanting to get more into it due to the rich feature-set of JavaScript.
See this thread for some hints: Learning & Using AppleScript & JavaScript for Automation (JXA)
-Chris
Hey Eduardo,
I think you won't see this kind of dialog very often, as most sites build their log-ins into the web page structure.
I use 1Password quite successfully with nearly all my protected websites.
First with Safari, then Google Chrome, and now Brave Browser.
Nevertheless – here's the basics of working with that dialog:
tell application "System Events"
tell application process "Google Chrome"
tell window "Sign in"
tell group "Sign in"
set theURL to value of static text 2
if theURL = "https://www.httpwatch.com" then
tell text field "Username"
set value to "MyUserName"
end tell
tell text field "Password"
set value to "MyPassword"
end tell
end if
end tell
end tell
end tell
end tell
-Chris
JXA documentation is still not as good as AppleScript, but you may find this helpful:
JXA Resources