如何使用Selenium处理Firefox中的安全警报 [英] How to handle security alert in Firefox with Selenium
问题描述
我正在使用selenium-webdriver和ruby编写自动化测试.
Chrome和chromedriver二进制文件确实可以很好地工作,但是Firefox存在与浏览器配置有关的问题,这使我的测试失败,但是它们通过了Chrome.
在Firefox中执行测试时,有时会收到此消息的警报:
尽管此页面已加密,但是您输入的信息是 通过未加密的连接发送,很容易被读取 第三方
这会中断执行.有没有办法在最近的Firefox版本(10+)中禁用此警告或使用Selenium处理此行为?
在为此寻找解决方案的过程中,我认为我可能在Capybara(v1.1.2)中发现了一个错误.
我设法使用以下方法解决了这个问题,而不是使用水豚的click
(这不允许我捕获异常),而是开始使用selenium-webdriver的click
方法. /p>
似乎当Firefox触发此警报框时,带有消息的字符串
尽管此页面已加密,但是您输入的信息是 通过未加密的连接发送,很容易被读取 第三方
作为object.native.click
的结果返回,否则返回字符串
好
返回.
# Define the click method in ruby and call it when you're executing a 'click'
# Public: Click the object.
#
# object - Capybara::Node::Element object to click.
def click object
return_string = object.native.click
check_firefox_alertbox if return_string == "ok"
end
def check_firefox_alertbox
if @current_browser == :firefox
@session.driver.browser.switch_to.alert.accept
end
rescue Exception => e
puts e
end
I'm using selenium-webdriver with ruby to write automated tests.
Chrome and the chromedriver binary work really well, but I have an issue with Firefox that is related to the configuration of the browser and that's making my tests fail, whereas they pass with Chrome.
When executing the tests in Firefox, sometimes I get an alert with this message:
Although this page is encrypted, the information you have entered is to be sent over an unencrypted connection and could easily be read by a third party
And it breaks the execution. Is there a way of disabling this warning in recent Firefox versions (10+) or handling this behavior with Selenium?
In the process of finding a solution for this, I think I might have found a bug in Capybara (v1.1.2).
I managed to get around this problem using the following approach, instead of using the click
from capybara (which would not allow me to capture an exception), I started using the click
method from selenium-webdriver.
It seems that when Firefox triggers this alertbox, a string with the message
Although this page is encrypted, the information you have entered is to be sent over an unencrypted connection and could easily be read by a third party
is returned as a result of object.native.click
, otherwise the string
ok
is returned.
# Define the click method in ruby and call it when you're executing a 'click'
# Public: Click the object.
#
# object - Capybara::Node::Element object to click.
def click object
return_string = object.native.click
check_firefox_alertbox if return_string == "ok"
end
def check_firefox_alertbox
if @current_browser == :firefox
@session.driver.browser.switch_to.alert.accept
end
rescue Exception => e
puts e
end
这篇关于如何使用Selenium处理Firefox中的安全警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!