Reputation: 47
I have a scenario where popup may appear or may not appear depend on filter options selected. If its appear i do have to click on 'Proceed' button. Please find attached screenshot.[https://i.sstatic.net/B0tN9.png]
Here is the code:
<div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-front ui-draggable ui-resizable" tabindex="-1" role="dialog" aria-describedby="DisplayBCWarningPopUpId" aria-labelledby="ui-id-6" style="position: absolute; height: auto; width: 300px; top: 81px; left: 837px; display: block;" xpath="1">
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix"></div>
<div id="DisplayBCWarningPopUpId" class="ui-dialog-content ui-widget-content" style="width: auto; min-height: 92px; max-height: none; height: auto;">
<div id="ApplyFiltersModal">
<br>
This will override the following applied filters. Hover over pills to see content changes. Do you wish to proceed?
<table></table>
<div style="clear:both;"></div>
<div class="checkbox"></div>
<div class="btn-delete-custom-dashboard" style="padding-top:15px;">
<input type="button" value="Cancel" id="btnCancelOverrideBC" name="WidgetGenericButtonContainer" buttonenabled="true" class="button-layout WidgetGenericButtonEnabled">
<script></script>
<input type="button" value="Proceed" id="btnOkOverrideBC" name="WidgetGenericButtonContainer" buttonenabled="true" class="button-layout WidgetGenericButtonEnabled">
<script></script>
</div>
</div>
<script></script>
</div>
Once all filters get selected clicking on apply button and then if Popup get displays trying to click on button 'Proceed'. What i tried is
if(driver.findElement(By.xpath("//input[@id='btnOkOverrideBC']")).isDisplayed()); { driver.findElement(By.xpath("//input[@id='btnOkOverrideBC']")).click(); }
Upvotes: 1
Views: 404
Reputation: 7563
You can utilize .findElements
(with s
), this is return a list.
Check the size, if > 0
it means the element exists.
if(driver.findElements(By.xpath("//input[@id='btnOkOverrideBC']")).size()>0) {
driver.findElement(By.xpath("//input[@id='btnOkOverrideBC']")).click();
}
Upvotes: 1