【问题标题】:Reload Webpage in Google Chrome until HTML contains specific text在 Google Chrome 中重新加载网页,直到 HTML 包含特定文本
【发布时间】:2021-10-11 06:42:45
【问题描述】:

此代码适用于 Safari(重新加载网页直到 HTML 包含特定文本)。 如何为 Chrome 修复它?

tell application "Safari"

set keyword to "Authentication mail"
repeat
    set myWindow to current tab of first window
    activate
    
    do JavaScript "window.location.reload()" in myWindow
    
    repeat while (do JavaScript "document.readyState" in document 1) is not "complete"
        delay 0.5
    end repeat
    
    set pageContent to do JavaScript ("window.document.documentElement.outerHTML") in myWindow
    
    if pageContent contains keyword then
        beep beep beep
        exit repeat
    end if
    delay 2 -- wait a bit before running again
end repeat end tell

【问题讨论】:

标签: javascript google-chrome applescript loading automator


【解决方案1】:

我不知道你的目标网站,所以我无法测试下面的代码。

tell application "Google Chrome"
    set keyword to "Authentication mail"
    repeat
        set myWindow to active tab of first window
        tell myWindow
            activate
            execute javascript "window.location.reload();"
            repeat while (execute javascript "document.readyState;") is not "complete"
                delay 0.5
            end repeat
            set pageContent to execute javascript "window.document.documentElement.outerHTML;"
            if pageContent contains keyword then
                tell current application to beep (beep (beep))
                exit repeat
            end if
            delay 2 -- wait a bit before running again
        end tell
    end repeat
end tell

【讨论】:

  • RE:“我不知道你的目标网站,所以我无法测试下面的代码。” -- 由于此网页包含keyword,您可以在此页面上对其进行测试。
  • user3439894,伙计!你是最伟大的!谢谢!它适用于常规窗口/页面。但是模态窗口有问题(class="modal-open")。您对模态窗口和弹出窗口有什么想法吗?
  • @Дмитрий Чудотворец,我刚刚对 gurkensaas 的回答做了一个小的修改,所以你应该感谢 gurkensaas 而不是我。也就是说,请看一下:What should I do when someone answers my question? RE:“你对模态窗口和弹出窗口有什么想法吗?” - 没有任何适当的上下文,我无话可说。您应该提出另一个问题,提供所有相关详细信息。
  • gurkensaas,非常感谢!伙计们,你们是?
  • @ДмитрийЧудотворец 如果您喜欢我的回答,请考虑接受它,以便其他搜索相同内容的人可以找到它。
猜你喜欢
  • 2017-07-01
  • 2013-10-15
  • 2014-10-13
  • 2012-11-16
  • 1970-01-01
  • 2017-09-13
  • 2013-09-11
  • 2015-01-06
  • 2017-06-23
相关资源
最近更新 更多