0

I am trying to click on OK button in dialog box. How can I find xpath to find the button and click to close the window. It is not in any Iframe. Here is my Code:

    `<div id="YesNoDialogBox" class="dialogbox errorDialog firepath-
 matching-node" style="display: block;">
 <div class="errWarnMsg">
<div class="popupHeaderContainer">
<div class="imgicon"><img src="/web/images/error.png" class="vMiddle"  
tabindex=""></div>
	  <h1>Warning message</h1>
	  <!-- Start: Warehouse change confirmation popup --><a href="#" id="close" class="closeClass warehouseCancel" tabindex=""> 
	  <img src="/web/images/close.png" class="closeIcon errWarnIcoClose" tabindex="">
	  </a>
	  <div class="clear"></div>	
	  <div class="msgBody paddingTopBtm2 textLeft padLeft10 warehouseText" style="">
				<span class="warningText" id="errorTextWarning">
				 Please Confirm to change warehouse
				 <br><br>
  					 Do you want to continue?
				</span>  
	  </div>
	  <div class="msgBody paddingTopBtm2 textLeft padLeft10 customerText" style="display:none">
		<span class="warningText" id="errorTextWarning">
			Please Confirm to change Customer
			<br><br>
  				Do you want to continue?
		</span> 		  
	  </div>
	  <div id="dialogboxNav" class="padding10 textLeft padLeft10 marginleft40">  
		<button class="enterSubmit btnInactive" name="btn_delete" id="warehouseOk" tabindex="">Yes</button>
		
		<a href="javascript:;" id="cancelDialog" class="formblue_link closeClass warehouseCancel" tabindex="">No</a>
	  </div>
</div>
 </div>
</div>`<div id="YesNoDialogBox" class="dialogbox errorDialog firepath-
     matching-node" style="display: block;">
     <div class="errWarnMsg">
    <div class="popupHeaderContainer">
      <div class="imgicon"><img src="/web/images/error.png" class="vMiddle" tabindex=""></div>
		  <h1>Warning message</h1>
		  <!-- Start: Warehouse change confirmation popup --><a href="#" id="close" class="closeClass warehouseCancel" tabindex=""> 
		  <img src="/web/images/close.png" class="closeIcon errWarnIcoClose" tabindex="">
		  </a>
		  <div class="clear"></div>	
		  <div class="msgBody paddingTopBtm2 textLeft padLeft10 warehouseText" style="">
					<span class="warningText" id="errorTextWarning">
					 Please Confirm to change warehouse
					 <br><br>
  					 Do you want to continue?
					</span>  
		  </div>
		  <div class="msgBody paddingTopBtm2 textLeft padLeft10 customerText" style="display:none">
			<span class="warningText" id="errorTextWarning">
				Please Confirm to change Customer
				<br><br>
  				Do you want to continue?
			</span> 		  
		  </div>
		  <div id="dialogboxNav" class="padding10 textLeft padLeft10 marginleft40">  
			<button class="enterSubmit btnInactive" name="btn_delete" id="warehouseOk" tabindex="">Yes</button>
    		
    		<a href="javascript:;" id="cancelDialog" class="formblue_link closeClass warehouseCancel" tabindex="">No</a>
		  </div>
    </div>
 </div>
</div>

1
  • There are multiple yes/no buttons are present in provided HTML, which one do you want to locate and click?? Commented Oct 19, 2016 at 15:09

2 Answers 2

1

I think you're pasting same dialog window HTML two times. Assuming there is only one dialog window.

You should try using WebDriverWait to wait until dialog window visible and enable to click desired element as below :-

WebDriverWait wait = new WebDriverWait(driver, 10);
  • If you want to click on Yes button try as :-

    wait.until(ExpectedConditions.elementToBeClickable(By.id("warehouseOk"))).click();
    
  • If you want to click on No button try as :-

    wait.until(ExpectedConditions.elementToBeClickable(By.id("cancelDialog"))).click();
    
  • If you want to click on Close button try as :-

    wait.until(ExpectedConditions.elementToBeClickable(By.id("close"))).click();
    

Note :- There is no need to use xpath locator, desired element could be locate easily using By.id() locator.

Sign up to request clarification or add additional context in comments.

Comments

1

You should be able to match by the ID:

//button[@id="warehouseOk"]

This article cites some useful examples of HTML XPath queries.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.