我正在使用AppleScript来打开在线会议。在这里的5个标签中,我应该点击绿色(当前会议)选项卡。是否知道如何getElementBy‘背景’颜色。
to clickClassName(theClassName, elementnum)
tell application "Safari"
do JavaScript "document.getElementsByClassName('" & theClassName & "')[" & elementnum & "].click();" in document 1
end tell
end clickClassName
tell application "Safari"
activate
open location "https://myclass.lpu.in/"
delay 5
tell application "System Events" to tell process "Safari"
keystroke "USERNAME"
delay 0.2
keystroke tab
delay 0.2
keystroke "PASSWORD"
delay 1
keystroke return
delay 5
end tell
end tell
clickClassName("btn stretched-link text-white w-100", 0)最后,我需要添加一个函数来打开那个绿色选项卡。
发布于 2021-09-09 16:53:31
我会帮你解决这个问题。您不能将我的解决方案归功于其他用户,否则我再也不会帮助您了。在脚本的末尾添加以下内容。
set classNames to {"fc-time-grid-event fc-event fc-start fc-end", "fc-time-grid-event fc-event fc-start fc-end fc-time-grid-event-inset"}
set notFounded to true
tell application "Safari"
repeat with className in classNames
if notFounded then
-- count all elements of indicated class
set theCount to (do JavaScript "document.getElementsByClassName(className).length;" in document 1) as integer
if theCount > 0 then -- find element with "background: green" and click it
repeat with i from 0 to theCount - 1
set theStyle to (do JavaScript "(document.getElementsByClassName(className)[" & i & "]).getAttribute('style');" in document 1) as text
if theStyle contains "background: green;" then
do JavaScript "(document.getElementsByClassName(className)[" & i & "]).click();" in document 1
set notFounded to false
exit repeat
end if
end repeat
end if
end if
end repeat
end tellhttps://stackoverflow.com/questions/69115895
复制相似问题