AppleScript点击带有颜色的网页

AppleScript to click on webpage with colour

我正在使用 AppleScript 打开在线会议。 Here among 5 tabs i should click on the green colour(current meeting) tab. 知道如何获取 ElementBy 'background' 颜色。

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)

最后我需要添加一个功能来打开那个绿色标签。

As in the picture there are 5 tags for 5 meetings ClassName is same so only background colour is unique in them

我会帮你解决的。您不得将我的解决方案归功于其他用户,否则我将永远不会再帮助您。在脚本末尾添加以下内容。

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 tell