Reputation: 60
I'm trying to click on a popup confirmation alert using Selenium Webdriver / Ruby, but even with the xpath I can't click on the OK or Cancel button.
(popup window: https://i.sstatic.net/oQHDH.jpg)
HTML code:
<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>
Code I tried:
browser.find_element(:xpath => '//*[@id="confirm1545919261219_content"]/div/div[2]/a[2]/span/span').click
and
browser.find_element(:xpath => '//td[.="Cancel"]').click
Thanks for ur time
Upvotes: 0
Views: 337
Reputation: 2814
do you have any errors while trying to click?
try following locator:
browser.find_element(:xpath, "//span[@class='rwInnerSpan' and text()='OK']").click;
browser.find_element(:xpath, "//span[@class='rwInnerSpan' and text()='Cancel']").click;
Upvotes: 1