如何单击“弹出确认”警报(Selenium Webdriver / Ruby)

时间:2018-12-27 14:09:35

标签: ruby selenium-webdriver

我试图使用Selenium Webdriver / Ruby来单击弹出确认警报,但是即使使用xpath,我也无法单击“确定”或“取消”按钮。

(弹出窗口:https://imgur.com/2E8dqKe

HTML代码:

<div>
  <a onclick="$find('confirm1545915453689').close(true);" class="rwPopupButton" href="javascript:void(0);"><span class="rwOuterSpan"><span class="rwInnerSpan">OK</span></span></a>
  <a onclick="$find('confirm1545915453689').close(false);" class="rwPopupButton" href="javascript:void(0);"><span class="rwOuterSpan"><span class="rwInnerSpan">Cancel</span></span></a>
</div>

我尝试的代码:

browser.find_element(:xpath => '//*[@id="confirm1545919261219_content"]/div/div[2]/a[2]/span/span').click 

browser.find_element(:xpath => '//td[.="Cancel"]').click

感谢您的时间

1 个答案:

答案 0 :(得分:0)

尝试单击时是否有任何错误?

尝试以下定位器:

browser.find_element(:xpath, "//span[@class='rwInnerSpan' and text()='OK']").click;
browser.find_element(:xpath, "//span[@class='rwInnerSpan' and text()='Cancel']").click;