Satyanarayana Pola
Satyanarayana Pola

Reputation: 43

selenium : I would like to click on " OK button" on pop up which also has some input option to provide name

Following is the code i have , I have pop up which has one input element and two buttons ok and cancel i wan to click on OK button. please help me i tried locating using alert but its not working

<div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-front ui-dialog-buttons" style="display: block; height: auto; width: 350px; top: 150.5px; left: 465px; z-index: 101;" tabindex="-1" role="dialog" aria-describedby="groups-dialog" aria-labelledby="ui-id-3">
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
<div id="groups-dialog" class="dialog ui-dialog-content ui-widget-content" style="width: auto; min-height: 15px; max-height: none; height: auto;">
<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
<div class="ui-dialog-buttonset">
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="button" role="button">
<span class="ui-button-text">OK</span>
</button>
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="button" role="button">
<span class="ui-button-text">Cancel</span>
</button>
</div>
</div>
</div>
<div class="ui-widget-overlay ui-front" style="z-index: 100;"></div>

Upvotes: 1

Views: 195

Answers (2)

Satyanarayana Pola
Satyanarayana Pola

Reputation: 43

driver.findElement(By.xpath("(//button[@type='button'])[2]")).click();

Above code is working for me

Upvotes: 0

Andersson
Andersson

Reputation: 52665

You don't have to handle pop-up as alert if it's not generated by alert(), but it's just an embedded div element

Try to locate target button using XPath:

//button[span[text()="OK"]]

Upvotes: 2

Related Questions