I'm unable to click a button and an exception is thrown as unable to locate element and exception throws on the marked lines of the screenshot.
The button takes some time to load and I have increased the time to 100 seconds, yet that didn't fix the error.
Code:
public static WebElement viewShipment(WebDriver driver, String mskuType) {
WebElement noOfShipment = driver.findElement(By.xpath(".//*[@id='fba-core-workflow-shipment-summary-shipment']"));
WebDriverWait wait = new WebDriverWait(driver, 15);
List<WebElement> shipmentList = noOfShipment.findElements(By.tagName("tr"));
int shipmentCount = shipmentList.size();
for (int row=1;row<shipmentCount;row=+1)
{
WebElement onOfSkuWE= driver.findElement(By.xpath(".//*[@id='fba-core-workflow-shipment-summary-shipment']/tr["+row+"]/td[3]"));
String noOfSku = onOfSkuWE.getText();
int noOfSkuValue = Integer.parseInt(noOfSku);
for(int i=0;i<2;i++)
{
try{
if(mskuType.equalsIgnoreCase("single"))
{
if(noOfSku.equalsIgnoreCase("1"))
{
Thread.sleep(10000);
WebElement workOnShipmentWE = driver.findElement(By.xpath(".//*[@id='fba-core-workflow-shipment-summary-shipment']/tr["+row+"]/td[6]/button"));
wait.until(ExpectedConditions.visibilityOf(workOnShipmentWE));
workOnShipmentWE.click();
break;
}
}
else if(mskuType.equalsIgnoreCase("multiple"))
{
if(noOfSkuValue>1)
{
WebElement moreThanOneUnit = driver.findElement(By.xpath(".//*[@id='fba-core-workflow-shipment-summary-shipment']/tr["+row+"]/td[6]/button"));
wait.until(ExpectedConditions.elementToBeClickable(moreThanOneUnit));
moreThanOneUnit.click();
break;
}
}
}
catch(Exception e)
{
driver.navigate().refresh();
e.getMessage();
}
}
}
return element;
}
HTML:
<tbody id="fba-core-workflow-shipment-summary-shipment">
<tr>
<td>FBA (11/3/16 9:32 PM) - 1</td>
<td>FBA43K62MB</td>
<td class="number total-line-items">1</td>
<td class="number total-quantity">3</td>
<td>
<td>
<button class="amznBtn btn-lg-pri-arrowr" onclick="window.location='#FBA43K62MB/prepare'" style="width: 28ex;" type="button" name="Work on shipment">
<span>Work on shipment</span>
</button>
<p class="action-links content-bottom">
<p class="action-links">
<p/>
</td>
</tr>
<tr style="display: none;">
<tr>
<tr style="display: none;">
<tr>
<tr style="display: none;">
</tbody>