I want to use JavaScript for my script.
I have created an object
of JavaScriptExecutor
, but executeScript()
method is not present. It shows error when I use executeScript()
method.
This is the code I have used:
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.JavascriptExecutor;
public class GetDomain_JS {
public static void main(String[] args) {
WebDriver driver=new FirefoxDriver();
driver.get("http://only-testing-blog.blogspot.in/2013/11/new-test.html");
driver.manage().window().maximize();
System.out.println(driver.getCurrentUrl());
JavaScriptExecutor js=(JavaScriptExecutor) driver;
String domain_name=(String) js.executeScript("return document.domain");
System.out.println(doamin_name);
}
}
It works for me; you had a mistake on JavaScriptExecutor
with upper case S
. Instead, you should have javascriptExecutor
with lower case s
.
Try this code:
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
public class GetDomain_JS {
public static void main(String[] args) {
WebDriver driver=new FirefoxDriver();
driver.get("http://only-testing-blog.blogspot.in/2013/11/new-test.html");
driver.manage().window().maximize();
System.out.println(driver.getCurrentUrl());
JavascriptExecutor js=(JavascriptExecutor) driver;
String domain_name=(String) js.executeScript("return document.domain");
System.out.println(domain_name);
}
}
This works for me!! Please thumps up if it does for you!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With