Issue
I've one situation where i need to handle no such element present exception,below is the scenario.
1.Customer is registered 2.Customer is not registered 3.Fresh Customer
For register customer i'm able to get register card number using xpath but fresh customer there is no such customer details display in the web table grid,in this situation my condition is not working and showing no such element present.
For Example:
Register Customer
Mobile No,First Name,Last Name ,Card No etc in customer details web table grid
String card_no=driver.findElement(By.xpath("//td[@aria-describedby='CustomerGrid_cardNo']")).getText();
System.out.println(card_no);
if(card_no.length()==0){
System.out.println("Customer is not register and proceeding for registration");
driver.findElement(By.id("cardNo")).sendKeys("39409297");
driver.findElement(By.id("Btn")).click();
Thread.sleep(2500);
}else{
System.out.println("Customer Mobile No is already registered -"+card_no);
}
Fresh Customer:
There is no such details will display in Customer web-table grid details.It is empty,and i need to register this fresh customer.Please provide solution how to write condition for this.
when empty
<table width="470" cellspacing="0" cellpadding="0" border="0" align="center">
<tbody>
<tr>
<tr>
<td>
<div id="gbox_CustomerGrid" class="ui-jqgrid ui-widget ui-widget-content ui-corner-all" dir="ltr" style="width: 570px;">
<div id="lui_CustomerGrid" class="ui-widget-overlay jqgrid-overlay"></div>
<div id="load_CustomerGrid" class="loading ui-state-default ui-state-active" style="display: none;">Loading...</div>
<div id="gview_CustomerGrid" class="ui-jqgrid-view" style="width: 570px;">
<div class="ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix" style="display: none;">
<div class="ui-state-default ui-jqgrid-hdiv" style="width: 570px;">
<div class="ui-jqgrid-bdiv" style="height: 300px; width: 570px;">
<div style="position:relative;">
<div></div>
<table id="CustomerGrid" class="ui-jqgrid-btable" cellspacing="0" cellpadding="0" border="0" tabindex="1" role="grid" aria-multiselectable="false" aria-labelledby="gbox_CustomerGrid" style="width: 552px;">
</div>
</div>
</div>
with data:
<table id="CustomerGrid" class="ui-jqgrid-btable" cellspacing="0" cellpadding="0" border="0" tabindex="1" role="grid" aria-multiselectable="false" aria-labelledby="gbox_CustomerGrid" style="width: 552px;">
<tbody>
<tr class="jqgfirstrow" style="height:auto" role="row">
<td aria-describedby="CustomerGrid_cardNo" title="7348054" style="text-align:center;" role="gridcell">7348054</td>
</tr>
Solution
You can try like below,
int card_no=driver.findElements(By.xpath("//td[@aria-describedby='CustomerGrid_cardNo']")).size();
System.out.println(card_no);
if(card_no==0){
System.out.println("Customer is not register and proceeding for registration");
driver.findElement(By.id("cardNo")).sendKeys("39409297");
driver.findElement(By.id("Btn")).click();
Thread.sleep(2500);
}else{
System.out.println("Customer Mobile No is already registered -"+card_no);
}
Answered By - Murthi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.