Watir Webdriver:测试在模式外部单击不会关闭它

Watir Webdriver: testing that clicking outside a modal does not close it

假设我有一个模态。

@my_modal = @brower.div(id: 'TheModal')

假设我有一个调出模态(在本例中为黄瓜)的测试

 Given I ...
 When I ...
 Then "My Modal" is visible
 When I click outside the modal
 Then "My Modal" is visible

现在定义在模式外单击的步骤:

 When /^I click outside the modal$/ do
   # what do I put here?
 end

有什么想法吗?

我刚刚尝试了 @browser.element(xpath: '//html').click 基于 How to simulate mouse click on blank area in website by Selenium IDE?。我收到错误 Selenium::WebDriver::Error::UnknownError: unknown error: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.

Watir 只允许您点击可见的元素。对于大多数模态实现,只有模态内部的元素才会被视为可见。

尝试:@browser.element.wd.click

如果还是不行,可以分享一下 html。

我最终得到了这个 @browser.driver.action.move_to(@browser.div(id: 'js-overlay').wd, 0, 0).click.perform

背景中有一个 div 使一切都变暗,div#js-overlay。通常用 `@browser.div(id: 'js-overlay') 单击它不起作用 b/c 它在模态所在的中间单击,所以这就是为什么有额外的业务单击该特定 div 的左上角(感谢 Justin Ko!)。