首页 > 解决方案 > 找不到定位器时如何跳过特定的 WebElement 进程?

问题描述

prinBalAgencyComm.sendKeys(testData.get("agencyCommissionPB"));

prinBalClientRem.sendKeys(Keys.TAB);

prinBalFrom2.sendKeys(testData.get("fromFB2")); //Locator not found

prinBalAgencyCommLast.sendKeys(testData.get("agencyCommissionLastPB")); //how to execute this line without fail

标签: selenium

解决方案


您可以通过使用 try catch finally 来处理这个问题。

try{
    //code that can result in an exception
    prinBalAgencyComm.sendKeys(testData.get("agencyCommissionPB"));
    prinBalClientRem.sendKeys(Keys.TAB);
    prinBalFrom2.sendKeys(testData.get("fromFB2"));
}catch(Exception e)
{   
    //actions you want to take in case your locator isnt found or another exception occurs
    System.out.println("Exception occured" + e.getMessage());
}finally
{   //the line to be executed without fail
    prinBalAgencyCommLast.sendKeys(testData.get("agencyCommissionLastPB"));
}

推荐阅读