JavaScript Executor using Selenium WebDriver

0 votes

I am using JavaScript for my code.

I used an object of JavaScriptExecutor, but executeScript() method is not present. It shows error when I use executeScript() method.

Below is my code:

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.JavascriptExecutor;

public class NewDemo{

    public static void main(String[] args) {

        WebDriver driver=new FirefoxDriver();

        driver.get("http://google.com");

        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);

    }

}
Apr 9, 2018 in Selenium by xyz
• 1,550 points
227 views

1 answer to this question.

0 votes

Its working fine but the problem in your code is with JavaScriptExecutor, i.e. s should be in lower case

See this or us this:

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.JavascriptExecutor;

import org.openqa.selenium.WebDriver;

public class NewDemo {

public static void main(String[] args) {

    WebDriver driver=new FirefoxDriver();

    driver.get("http://google.com ");

    driver.manage().window().maximize();

answered Apr 9, 2018 by Vardy
• 2,250 points

Related Questions In Selenium

0 votes
1 answer

Capturing JavaScript errors with Selenium WebDriver using Java

There is logs Beta version in WebDriver driver.manage().logs().get(LogType.BROWSER); Console output will be ...READ MORE

answered May 18, 2018 in Selenium by Samarpit
• 5,130 points
225 views
0 votes
1 answer
0 votes
1 answer

How can I handle Javascript Alert popup using Ruby Selenium webdriver?

Hey Usman, you can use driver.switch_to.alert method ...READ MORE

answered Aug 26 in Selenium by Abha
• 24,440 points
37 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,090 points
760 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
1,001 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
713 views
0 votes
1 answer

Select an item from a dropdown list using Selenium WebDriver

Use this then it will work - new ...READ MORE

answered Apr 9, 2018 in Selenium by Vardy
• 2,250 points
2,374 views
0 votes
1 answer

Using gettext() method for the specific element using Selenium WebDriver

Mistake is that u r printing the ...READ MORE

answered Apr 10, 2018 in Selenium by Vardy
• 2,250 points
6,564 views