Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8480343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:16:10+00:00 2026-06-10T19:16:10+00:00

I am helping to build an automation framework to test our website. Since the

  • 0

I am helping to build an automation framework to test our website. Since the test cases must run against Chrome, Firefox and IE, we are currently passing around a WebDriver object for our driver. This object will in reality be either a ChromeDriver, FirefoxDriver, or InternetExplorerDriver, as the case may be.

The problem I’m having is that I want to have this driver open up a new window in order to validate a test. The only method I’ve found to do this involves executing javascript – see here.

In order to execute javascript, a driver must implement the JavascriptExecutor interface. All of the drivers we will use are in fact JavascriptExecutors, but since we are using the WebDriver interface, this is not guaranteed. I am trying to get the javascript running, at least as a proof of concept, but I also want to know how to properly organize our driver object so that it can execute javascript without having to explicitly state which of the three drivers it is.

Here is something that I tried just to test the javascript method of opening a new window. It did not work:

    if (ChromeDriver.class.isInstance(driver)) {
            ChromeDriver chrome = (ChromeDriver)driver;
            chrome.executeScript("window.open()");
        }
    for (String handle : driver.getWindowHandles()) {
            System.out.println(handle);
        }

In the above case, I was using Chrome for testing so I knew that the driver was in fact a ChromeDriver. I am guessing that the code failed to open a new window because I was instantiating a new driver object and I assume this doesn’t really work with Selenium. Had it worked, I would’ve moved on to try to identify the windows (using driver.getWindowHandles) and load a URL in the new window.

So – is the reason the code failed to open a new window that I was creating/casting a new driver object which Selenium disliked? If so, what is the proper solution? Do I need to create a new interface sandwiched between the Chrome, Firefox, and IE drivers and the JavascriptExecutor interface – something like this?

     public interface SpecialDriver extends WebDriver, JavascriptExecutor {

     }

This doesn’t seem to work – at least, I cannot assign a ChromeDriver to a SpecialDriver, because ChromeDriver does not explicitly implement my new combined interface, even though it implements both WebDriver and JavascriptExecutor. Am I barking up the wrong tree entirely with this approach? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:16:11+00:00Added an answer on June 10, 2026 at 7:16 pm

    The correct approach would be to do something like the following:

    // WARNING! Untested code. Not guaranteed
    // to work or even compile.
    // Assume driver is a valid WebDriver object
    // TODO: Wrap in try-catch to handle invalid 
    // cast exception
     ((JavascriptExecutor)driver).executeScript("return 'your script goes here';");
    

    While you’re correct that there’s no guarantee a WebDriver object will also implement JavascriptExecutor, the reality is that all current implementations do so.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a CM and am responsible for our Continuous build process, and helping the
I am helping my daughter build an asp.net website that has an Access database.
I'm currently helping build an API that I would like 3rd party developers to
I've recently been tasked with helping build a database for a dating website. I'm
I am helping to maintain this website http://www.groupme.my/national/ For certain deals with a long
I am helping another programmer build an install program that needs to locate the
I'm helping a colleague build a project that allows people to say where they
We want to build into our software the capability to build SQL queries freehand
The NetBeans command to run an Ant build for a project is F11 .
I'm helping build an Android application that is in synchronization with a Ruby on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.