Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 正在获取空指针异常。。?_Java_Selenium - Fatal编程技术网

Java 正在获取空指针异常。。?

Java 正在获取空指针异常。。?,java,selenium,Java,Selenium,无法解决…任何人都可以帮我解决请检查loctType,loctValue不是null。另外,在执行try catch操作之前,检查locter是否为notnull也很好。您从哪里获得NPE?它正在按要求打印locvalue和loctype。函数调用中存在一些问题,请更改此值。WebDriverWait wait=新建WebDriverWait(driver,10);wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xp

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

请检查
loctType
loctValue
不是
null
。另外,在执行
try catch
操作之前,检查
locter
是否为
not
null也很好。

您从哪里获得NPE?它正在按要求打印locvalue和loctype。函数调用中存在一些问题,请更改此值。WebDriverWait wait=新建WebDriverWait(driver,10);wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(loctValue));在使用findBy…..之前,请将其用于元素。。。。。
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;

    }