首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >AppleScript点击带有颜色的网页

AppleScript点击带有颜色的网页
EN

Stack Overflow用户
提问于 2021-09-09 09:46:09
回答 1查看 70关注 0票数 0

我正在使用AppleScript来打开在线会议。在这里的5个标签中,我应该点击绿色(当前会议)选项卡。是否知道如何getElementBy‘背景’颜色。

代码语言:javascript
复制
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)

最后,我需要添加一个函数来打开那个绿色选项卡。

如图所示,5次会议有5个标签,ClassName是相同的,所以只有背景颜色是唯一的。

EN

Stack Overflow用户

回答已采纳

发布于 2021-09-09 16:53:31

我会帮你解决这个问题。您不能将我的解决方案归功于其他用户,否则我再也不会帮助您了。在脚本的末尾添加以下内容。

代码语言:javascript
复制
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
票数 -1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69115895

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档