Spent 1 day on finding the solution to the following problem:
Can't execute even simple js code using selenium WD. It always returns NullPointerException. Already read tonns of answers but still can't find the reason. The code below is the code after 1 day investigation (I just have tried everything):
WebDriver driver2;
JavascriptExecutor js = (JavascriptExecutor)driver2;
driver.get(baseUrl+ "/");
js.executeScript("return showAlert()");
Here is the original code that is not working as well:
public class DPT_class {
private WebDriver driver;
@Before
driver = new FirefoxDriver();
JavascriptExecutor js = (JavascriptExecutor) driver;
@Test
//some testing code here
driver.get(baseUrl+ "/");
js.executeScript("return showAlert()");
}
the same thing for any other js code such as alert(document.title) with and without return and quotes. *baseUrl is predefined of course.
Thanks!
driver2
instance? – Smit Sep 26 '13 at 22:22driver2
, in which casejs
will not have a value either. Your compiler should be complaining that you are using a value which isn't "definitely assigned". – rutter Sep 26 '13 at 22:38