【问题标题】:Getting null pointer Exception..? [duplicate]获取空指针异常..? [复制]
【发布时间】:2016-07-29 08:41:39
【问题描述】:
public WebElement locater(String locter)
    {
        String[] value = locter.split("##");
        String loctValue = value[0];
        String loctType = value[1];



        try {
            if(loctType.equalsIgnoreCase("XP"))
            {


                loct = driver.findElement(By.xpath(loctValue));


            }
            else if(loctType.endsWith("id"))
            {
                loct = driver.findElement(By.id(loctValue));

            }
            else if(loctType.equalsIgnoreCase("linkText"))
            {
                loct = driver.findElement(By.linkText(loctValue));
            }
            else if(loctType.equalsIgnoreCase("partialLink"))
            {
                loct = driver.findElement(By.partialLinkText(loctValue));
            }
            else if(loctType.equalsIgnoreCase("cssSelect"))
            {
                loct = driver.findElement(By.cssSelector(loctValue));
            }
            else if(loctType.equalsIgnoreCase("name"))
            {
                loct = driver.findElement(By.name(loctValue));
            }
            else if(loctType.equalsIgnoreCase("tagname"))
            {
                loct = driver.findElement(By.tagName(loctValue));
            }

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.out.println(e.getMessage());
        }
        return loct;

    }

无法解决...任何人都可以帮助我

【问题讨论】:

  • 你从哪里获得 NPE?

标签: java selenium


【解决方案1】:

请检查loctTypeloctValue 不是null。在您的try catch 操作之前检查locter 是否也是not null 也很好。

【讨论】:

  • 它正在按要求打印 locvalue 和 loctype。函数调用存在一些问题
  • 用你的价值观改变这个。
  • WebDriverWait 等待 = new WebDriverWait(driver, 10); wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By .xpath(loctValue)));
  • 在使用 findBy 之前将其用于您的元素.....
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多