Hi there I am unable to run JavaScript using Web driver due to an Unresolved compilation problem
, can anyone point out where I am going wrong so I can run a real simple line of JavaScript when running a selenium web driver script?
package Check;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class java {
public static void main(String[] args) {
// TODO Auto-generated method stub
FirefoxDriver driver = new FirefoxDriver();
driver.get("https://www.google.co.uk/search?q=dreams");
WebDriver driver2 = new AnyDriverYouWant();
JavascriptExecutor js;
if (driver instanceof JavascriptExecutor) {
js = (JavascriptExecutor)driver;
}
js.executeScript("function showAlert() { alert('success'); }; showAlert()");
driver.quit();
}
}
Error details:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
AnyDriverYouWant cannot be resolved to a type
at Check.java.main(java.java:13)
I needed to force the page to wait and to instantiate the variable unconditionally, here is the revised code that works: