특정 웹 사이트에서 "검색"버튼을 클릭하는 데 문제가 있습니다. 웹 사이트는 구독 서비스이므로 "검사"모드에서 가져온 페이지의 사진과 코드를 첨부하고 있습니다.
내 코드 :
set myURL to "https://www.uptodate.com/contents/search"
tell application "Safari"
activate
make new document with properties {URL:myURL}
end tell
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.3
end repeat
end tell
inputByID("tbSearch", "myVar")
clickClassName("newsearch-submit", 0)
###InputByID###
to inputByID(theId, theValue)
tell application "Safari"
do JavaScript "document.getElementById('" & theId & "').value ='" & theValue & "';" in document 1
end tell
end inputByID
###ClickByClass###
to clickClassName(theClassName, elementnum)
tell application "Safari"
do JavaScript "document.getElementsByClassName('" & theClassName & "')[" & elementnum & "].click();" in document 1
end tell
end clickClassName
대안으로 사용할 수있는 UI 스크립팅 , 시스템 이벤트가 몇 가지 예비 적 키 입력을 .
다음 예제 AppleScript 코드 는 macOS High Sierra 1 에서 작동합니다 .
set myURL to "https://www.uptodate.com/contents/search"
tell application "Safari"
activate
make new document with properties {URL:myURL}
end tell
tell application "System Events"
repeat until (accessibility description of ¬
button 1 of UI element 1 of every group of toolbar 1 of window 1 of ¬
process "Safari" whose name = "Reload this page") contains "Reload this page"
delay 0.5
end repeat
end tell
tell application "Safari"
do JavaScript "document.getElementById('tbSearch').value ='PPE';" in document 1
end tell
tell application "System Events"
keystroke space
key code 51 -- # Press the delete key to remove the space.
keystroke return
end tell
UI element 1
to UI element 2
in the repeat
loop above.참고 : AppleScript 코드 의 예 는 바로 그 것이며 적절한 오류 처리 를 포함하지 않습니다 . 적절하거나 필요하거나 원하는대로 오류 처리 를 추가 할 책임은 사용자에게 있습니다 . 상기 봐 가지고 시도의 문 및 오류 문 에서 애플 스크립트 언어 가이드 . 오류 작업을 참조하십시오 . 또한, 사용 지연 명령은 예를 들어, 이벤트 적절한 사이 필요할 수 있습니다 로, 값 의 지연 적절하게 설정합니다. delay 0.5
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다