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
145 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,280 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
99 views
0 votes
1 answer
0 votes
1 answer

I tried to open a new website when a new tab is opened using Selenium Webdriver

Try this code: ArrayList<String> tabs = new ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,030 points
456 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,030 points
56 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
420 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
43 views
0 votes
1 answer
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,280 points
2,417 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.