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,560 points
1,502 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,360 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,910 points
1,745 views
0 votes
2 answers
0 votes
2 answers

What is the best way to handle a Javascript popup using Selenium Webdriver?

webDriver.switchTo().alert() it inbuild selenium only //Store the alert ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
10,933 views
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 27, 2019 in Selenium by Abha
• 28,140 points
2,326 views
0 votes
2 answers

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,500 points
13,771 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,187 views
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,910 points
7,263 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,901 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,360 points
7,791 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,360 points
28,747 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP