WebElement element = driver.findElement(By.id(pro.getProperty("")));
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("return arguments[0].text", element);
String cartCountSearchTab = ((String) ((JavascriptExecutor)driver).executeScript("returnarguments[0].text;",driver.findElement(By.id(pro.getProperty(""))))).replaceAll(" ", "");
int cartCountTab = Integer.parseInt(cartCountSearchTab);
上面的代码抛出空指针异常。
答案 0 :(得分:0)
在您的JavaScript中,关键字 return 后应该有空格,如下所示。
String cartCountSearchTab = ((String) ((JavascriptExecutor)driver).executeScript("return arguments[0].text;",driver.findElement(By.id(pro.getProperty(""))))).replaceAll(" ", "");