Schlagwort-Archive: safari

AppleScript: Javascript in Safari ausführen

force safari to load url. if url is loaded use javascript to submit form.
tell application "Safari" to open location ""
if my page_loaded(20) is true then
    tell application "Safari"
        tell document 1
            do JavaScript "document.getElementById('suchfeld').q.value='Applescript'; 
            if my page_loaded(20) is true then
                do JavaScript "var b = new Array(); 
for (var i=0;i<document.getelementbyid('filter').getelementsbytagname('a').length;i++) if="" documentgetelementbyid="" filter="" getelementsbytagname="" a="" iinnerhtmlindexof="" ct="">-1) 
window.location.href = document.getElementById('filter').getElementsByTagName('a')[i].getAttribute('href') 
            end if
        end tell
    end tell
    display dialog "There was a timeout"
end if

on page_loaded(timeout_value)
    set i to 0
    delay 1
    tell application "Safari"
        repeat until (do JavaScript "document.readyState" in document 1) is "complete"
            delay 0.5
            if i > timeout_value then return false
            set i to i + 1
        end repeat
        return true
    end tell
end page_loaded