Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 6993 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I have a problem getting Applescript to click a button on a web page. And although it is the only button on the page I cannot use the usual option of "keystroke return" as it simply doesn't work. My script goes like this and it is the line «click button "login"» that provokes the error. The problem does not stem from the password or User ID not being correct or entered as Safari does this automatically. Any ideas on remedying this?

tell application "Safari"

activate

make new document

set URL of document 1 to "https://www.orange.ch/footer/login"

end tell

if page_loaded(5) then

tell application "System Events"

tell application process "Safari"

click button "login"

end tell

end tell

else

display alert "The URL Has Not Loaded."

end if

on page_loaded(timeout_value)

delay 2

repeat with i from 1 to the timeout_value

tell application "Safari"

if (do JavaScript "document.readyState" in document 1) is "complete" then

return true

else if i is the timeout_value then

return false

end if

delay 1

end tell

end repeat

end page_loaded

Posted

I finally found a solution to all this. It isn't very elegant but at least it works. I realised this if you hit the tab key 16 times once the page had opened, the login button finally becomes operational. You only need then hit the return to login. So here's my script

tell application "Safari"

activate

make new document

set URL of document 1 to "https://www.orange.ch/footer/login"

end tell

if page_loaded(5) then

tell application "System Events"

tell application process "Safari"

keystroke tab

keystroke tab

keystroke tab

keystroke tab

keystroke tab

keystroke tab

keystroke tab

keystroke tab

keystroke tab

keystroke tab

keystroke tab

keystroke tab

keystroke tab

keystroke tab

keystroke tab

keystroke tab

keystroke return

end tell

end tell

else

display alert "The URL Has Not Loaded."

end if

on page_loaded(timeout_value)

delay 2

tell application "Safari"

repeat with i from 1 to the timeout_value

if (do JavaScript "document.readyState" in document 1) is "complete" then return true

delay 1

end repeat

end tell

return false

end page_loaded

This topic is 6993 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.