import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
public class oo {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","D:\\Java\\Lib\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.navigate().to("https://google.com");
JavascriptExecutor js = (JavascriptExecutor) driver;
Object s = js.executeScript("return document.body.innerHTML;",null).toString();
System.out.println(s);
driver.close();
}
}
Над кодом возвращается nullPointerException.
Exception in thread "main" java.lang.NullPointerException at java.util.Arrays.stream(Unknown Source) at java.util.stream.Stream.of(Unknown Source) at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:484) at oo.main(oo.java:25)
При удалении необязательного параметра объекта происходит ошибка компиляции.
Код:
JavascriptExecutor js = (JavascriptExecutor) driver;
Object s = js.executeScript("return document.body.innerHTML;").toString();
Ошибка:
Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method executeScript(String, Object[]) in the type JavascriptExecutor is not applicable for the arguments (String)
Использование Selenium-server-standalone-3.141.59.jar