У меня есть код, который открывает Safari для bing, вставляет что-то для поиска и выполняет поиск. Тем не менее, я пытаюсь заставить скрипт вводить поиск THEN go вниз и искать результаты автозаполнения, а не фактическое поисковое слово. До сих пор я не смог этого сделать. Вот разбивка:
set theURL to "https://www.bing.com"
tell application "Safari" to make new document with properties {URL:theURL}
tell application "System Events"
repeat until exists (UI elements of groups of toolbar 1 of window 1 of application process "Safari" whose name = "Reload this page")
delay 0.5
end repeat
end tell
inputByID("sb_form_q", "coronavirus")
delay 0.5
clickID("sb_form_q") -- Here is where it breaks down. Trying to "click" the search bar after pasting so that System Events can 'arrow down'to the autofill results.
tell application "System Events"
key code 125
key code 125
end tell
delay (random number from 5 to 15)
clickID("sb_form_go")
delay 0.5
tell application "System Events"
delay 1.5
keystroke "w" using command down
end tell
to inputByID(theID, theValue)
tell application "Safari"
do JavaScript " document.getElementById('" & theID & "').value ='" & theValue & "';" in document 1
end tell
end inputByID
to clickID(theID)
tell application "Safari"
do JavaScript "document.getElementById('" & theID & "').click();" in document 1
end tell
end clickID
В конечном счете, целью является случайный поиск результатов автозаполнения на основе введенных данных. Код до сих пор не работает и будет просто искать исходный текст ввода.