Selenium - 禁用弹出窗口阻止程序

时间:2013-02-26 17:25:59

标签: safari selenium-webdriver selenium-grid popup-blocker

我花了好几个小时用Selenium SafariSelenium Grid 2,然后才发现我需要禁用弹出窗口拦截器以允许我有一个登录弹出窗口。

我的问题是,有没有办法在使用RemoteWebDriver创建节点/网络驱动程序时,或在代码中创建{{1}}时,或两者都禁用弹出窗口拦截器?

否则,我必须手动记住通过自己打开浏览器来更改此设置。目的是让Selenium在多台机器上运行,因此能够以编程方式设置它是很棒的。

1 个答案:

答案 0 :(得分:0)

好的,这是我最后写的AppleScript:

tell application "System Events" to tell process "Safari"
    set frontmost to true
    keystroke "," using {command down}  -- open preferences
    delay 1
    tell window "Security"
        tell group 1
            tell group 1
                click checkbox "Block pop-up windows"
            end tell
        end tell
        key code 53  -- close preferences
    end tell
end tell

如果您将其另存为popup.as,则可以按以下方式运行:

$ osascript popup.as

请注意,这仅适用于本地,而不适用于像Sauce Labs这样的云服务。