Reputation: 33
I currently trying to test a dialog with Selenium WebDriver but the "Create Employee" button doesn't have an id nor a name. This is what the code looks like.
<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
<div class="ui-dialog-buttonset">
<button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false">
<span class="ui-button-text">Create Employee</span>
</button>
<button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false">
<span class="ui-button-text">Cancel</span>
</button>
</div>
<button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false">
<span class="ui-button-text">Create Employee</span>
</button>
<button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false">
<span class="ui-button-text">Cancel</span>
</button>
</div>
Can anyone provide me with the java code that will click the button in the dialog box? Thanks
Upvotes: 1
Views: 4775
Reputation: 4705
As an alternative to the xpath stuff, which I found troublesome for newbies, I found that jQueryUI dialog can add IDs to the results.
Instead of:
$("#stuff").dialog({
buttons: {
"Yes": function() {
write:
$("#stuff").dialog({
buttons: {
"Yes": { text: "Yes",
id: "#mystuff-yes",
click: function() {
Upvotes: 1
Reputation: 182
Try Below code.
driver.findelement(By.xpath("//button[@type='button']/span[text()='Create Employee']")).click();
Upvotes: 4
Reputation: 5502
If you don't have any way to select any element I would suggest the use of xpath
I would suggest installing some addons or extensions on your browser for getting the xpath
of the element you want to interact. Then Use that xpath for your purpose.
Upvotes: 0