Home > Back-end >  AppleScript wait for WebView of application to load
AppleScript wait for WebView of application to load

Time:10-21

I'm fighting with AppleScript for a day now and it's driving me crazy as hell. I can't manage to handle the wait of application WebView to load before allowing the script to continue.

I want to automate my login process to Cisco AnyConnect Mobility Client which is configured with 2 MFA over OneLogin Form.

When Cisco Launches it opens main window and second window in which the WebView login form loads. The load time of the WebView is not consistent so I need to wait until it exists until I can input anything without any arbitral delays.

Here is what I have so far.

property ciscoApp : "Cisco AnyConnect Secure Mobility Client"
property loginWindow : "Cisco AnyConnect Login"

tell application ciscoApp
    activate
end tell

repeat until application ciscoApp is running
    delay 0.5
end repeat

tell application "System Events" to tell process ciscoApp
    repeat until window loginWindow exists
        delay 0.5
    end repeat
    
    
    tell window loginWindow
        
        -- here I want to be able to wait until I can do inputs
        repeat until Web View of loginWindow exists
            delay 0.5
        end repeat
        log "ok"
    end tell
    
end tell

Accessibility Inspector Hierarchy

I would like either to wait for "OneLogin (HTML content)" to be visible/queryable or the one element below (text field). Really appreciate any help. AppleScripting seems so hard for me :D

CodePudding user response:

The problem I had was with the HTML Content element. I was able to figure out it can be queried with use of UI Element so this worked for my case

property targetApp : "Cisco AnyConnect Secure Mobility Client"
property loginWindow : "Cisco AnyConnect Login"

repeat until (button "Continue" of group 3 of UI element of scroll area 1 of group 1 of group 1 of window loginWindow of process targetApp exists)
  delay 0.1
end repeat
  • Related