Getting Null pointer exception while trying to validate SVG element when it does NOT exist in UI - JAVA/selenium

Viewed 14
 public void rushitem(String rushi) {
    try {
        stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT rfp_expdt_ind\n" +
                "\tFROM e2e_rfpr_o.wrkflw_ap0001_rfp where rfp_case_id ='RFP-U500-3134';");
        while (rs.next()) {
            rushitem_sql = rs.getString(rushi);
            System.out.println("Rush Indi from DB is : " + acctname_sql);
        }
    } catch (SQLException | NullPointerException e) {
        e.printStackTrace();
    }
}

public void validaterushitem() throws NullPointerException {
    JavascriptExecutor js = (JavascriptExecutor) driver;
    //  WebElement rush1 = driver.findElement(By.xpath("(//*[local-name()='svg'])[4]"));
    List<WebElement> rush = driver.findElements(By.xpath("(//*[local-name()='svg'])[4]"));
    int checkLink = rush.size();
   
        try {
               if (rushitem_sql.equals("Y")) {
                    System.out.println("match successful for rush indicator");
                    WebElement rush1 = driver.findElement(By.xpath("(//*[local-name()='svg'])[4]"));
                    js.executeScript("arguments[0].setAttribute('style','border: 3px solid green;')", rush1);
                } else System.out.println("match failed for rush indicator");

            }
         catch (NoSuchElementException e) {
            e.printStackTrace();
        } finally {
            System.out.println("case is not rush item");
        }
    }

Inside chrome webbrowser, screen has multiple tabs where, 'svg element' icon exists. If 'rushitem_sql' = N or no record exists in Database then 'svg element' icon should not exist.

Screen layout is as follows: chrome web browser has few tabs inside and each tab contains the element. I am navigating between each tab and verify icon exist or not. Issue: if rushitem_sql = Y then it all works fine but if rushitem_sql = N or no record exist in Database then tab1 works fine but navigating to tab 2 gives NULLPOINTEREXCEPTION. Need help with this please. I have tried many code changes but exception still there. what am i missing?

0 Answers
Related