我试图在弹出的JavaScript警报中单击“确定”以删除页面上的元素。我有以下内容:
assert element_present?(:css, "#add_foods_1 > table > tbody > tr > td.cf.cc2 > a.track_remove")
@driver.find_element(:css, "#add_foods_1 > table > tbody > tr > td.cf.cc2 > a.track_remove").click
assert_equal "This will delete this food from your foods eaten today. Click OK to continue or Cancel to return.", close_alert_and_get_its_text()
调用close_alert_and_get_its_text()
的定义代码为:
def close_alert_and_get_its_text(how, what)
alert = @driver.switch_to().alert()
alert_text = alert.text
if (@accept_next_alert) then
alert.accept()
else
alert.dismiss()
end
alert_text
ensure
@accept_next_alert = true
end
我很困惑如何只需单击“确定”即可关闭警报。警报上有一个OK和Cancel。