2
<div id="RadWindowWrapper_alert1579252675818" class="RadWindow RadWindow_Metro rwNormalWindow rwTransparentWindow" unselectable="on" style="width: 398px; height: 148px; position: absolute; transform: none; backface-visibility: visible; touch-action: none; visibility: visible; left: 84px; top: 113px; z-index: 3012;"><table cellspacing="0" cellpadding="0" class="rwTable" style="height: 148px;"><tbody><tr class="rwTitleRow"><td class="rwCorner rwTopLeft">&nbsp;</td><td class="rwTitlebar" style="cursor: move;"><div class="rwTopResize"><!-- / --></div><table align="left" cellspacing="0" cellpadding="0" class="rwTitlebarControls"><tbody><tr><td style="width: 16px;"><a class="rwIcon"></a></td><td><em unselectable="on" style="width: 318px;">Automax Message</em></td><td nowrap="" style="white-space: nowrap;"><ul class="rwControlButtons" style="width: 32px;"><li><a href="javascript:void(0);" class="rwCloseButton" title="Close"><span>Close</span></a></li></ul></td></tr></tbody></table></td><td class="rwCorner rwTopRight">&nbsp;</td></tr><tr class="rwContentRow"><td class="rwCorner rwBodyLeft">&nbsp;</td><td class="rwWindowContent" valign="top"><iframe name="alert1579252675818" src="javascript:'<html></html>';" frameborder="0" style="width: 100%; height: 100%; border: 0px; display: none;"></iframe><div id="alert1579252675818_content" style="">
    <div class="rwDialogPopup radalert" style="background-image: url(&quot;../Images/InteractionImages/AutomaxSuccess.png&quot;);">         
        <div class="rwDialogText" id="alert1579252675818_message">
        Location added successfully<br><br>             
        </div>

        <div>
            <a onclick="$find('alert1579252675818').close(true);" class="rwPopupButton" href="javascript:void(0);" tabindex="-1">
                <span class="rwOuterSpan">
                    <span class="rwInnerSpan">Ok</span>
                </span>
            </a>                
        </div>
    </div>
    </div></td><td class="rwCorner rwBodyRight">&nbsp;</td></tr><tr class="rwStatusbarRow" style="display: none;"><td class="rwCorner rwBodyLeft">&nbsp;</td><td class="rwStatusbar"><table align="left" cellspacing="0" cellpadding="0" style="width: 100%;"><tbody><tr><td style="width: 100%;"><input id="alert1579252675818_status" readonly="" unselectable="on" tabindex="-1"><label for="alert1579252675818_status" style="display: none;">status label</label></td></tr></tbody></table></td><td class="rwCorner rwBodyRight">&nbsp;</td></tr><tr class="rwFooterRow"><td class="rwCorner rwFooterLeft">&nbsp;</td><td class="rwFooterCenter">&nbsp;</td><td class="rwCorner rwFooterRight">&nbsp;</td></tr></tbody></table></div>
  1. Detailed HTML tag for 'Ok' button message.
  2. name="alert1579246138835" is changing when refreshing the page.
  3. HTML for popup / alert was present/visible on the page

1 Answers1

2

The desired element is a dynamic element so to locate and click() on the element you have to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.rwPopupButton > span.rwOuterSpan > span.rwInnerSpan"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='rwPopupButton']/span[@class='rwOuterSpan']/span[@class='rwInnerSpan' and text()='Ok']"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Expected condition is failed, the above 'Ok' message is present under a frame so i tried the given xpath and css selectors after and before driver. switchTo().defaultContent(); – Jayaram Ganeshan Jan 17 '20 at 07:00
  • If the element is with in an ` – undetected Selenium Jan 17 '20 at 07:15
  • The HTML you updated seems invalid. Instead of handcrafting can you copy the HTML as it is with in the webpage? – undetected Selenium Jan 17 '20 at 08:05
  • The HTML is copied as it is – Jayaram Ganeshan Jan 17 '20 at 08:26
  • With the updated HTML the locators I have provided within this answer still stands **valid** where as the element is outside the ` – undetected Selenium Jan 17 '20 at 09:09
  • Updated with new HTML tag contains alert elements. Can you please confirm this? – Jayaram Ganeshan Jan 17 '20 at 09:24
  • driver.findElement(By.xpath("//span[contains(text(), 'Ok')]/ancestor::a")).click(); Fixed my issue – Jayaram Ganeshan Jan 20 '20 at 09:47