gpt4 book ai didi

javascript - 使用Applescript和Javascript : get checkbox IDs from webpage,循环,如果结束匹配字符串单击复选框

转载 作者:行者123 更新时间:2023-12-02 22:55:07 24 4
gpt4 key购买 nike

我正在尝试使用 applescript 和 javascript 单击 https://calendar.google.com/calendar/syncselect 上的所有复选框whos 元素 ID 以相关域结尾。
ElementID 示例为“person@domain.com”

当您知道确切的 ID 并且可以先指定它时,这才有效:

tell application "Safari"
open location "https://calendar.google.com/calendar/syncselect"
delay 3
do JavaScript "
document.getElementById('person@domain.com').click();
" in document 1
end tell

这是尝试循环的循环尝试:

to goToWebPage(theWebPage)
tell application "Safari"
activate
set URL of document 1 to theWebPage
end tell
end goToWebPage

to clickID(theId) --creates a function that we can use over and over again instead of writing this code over and over again

tell application "Safari" -- lets AppleScript know what program to controll

do JavaScript "document.getElementById('" & theId & "').click();" in document 1 -- performs JavaScript code that clicks on the element of a specific id

end tell -- tells Applescript you are done talking to Safari

end clickID -- lets AppleScript know we are done with the function

goToWebPage("https://calendar.google.com/calendar/syncselect")
clickID("person@domain.com")

基于示例:http://www.cubemg.com/how-to-click-a-button-on-a-web-page-with-applescript/

基本上,要同步的日历列表会发生变化,因此我想创建所有复选框 ID 的数组/列表。如果任何 ID 以domain.com 结尾,则循环遍历它们。单击该框。

最佳答案

今天早上找到了解决方案,感谢此处的文档: https://developer.mozilla.org/en-US/docs/Web/API/NodeList

tell application "Safari"
open location "https://calendar.google.com/calendar/syncselect"
delay 3
do JavaScript "

var list = document.querySelectorAll('input[type=checkbox]');
for (var checkbox of list) {
checkbox.checked = true;
};
" in document 1

document 1
end tell

关于javascript - 使用Applescript和Javascript : get checkbox IDs from webpage,循环,如果结束匹配字符串单击复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58018090/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com