Use JavascriptExecutor in Page-Object-Model

59
February 13, 2018, at 4:33 PM

there has been an automation side project I've been working on in my spare time and I've been trying to incorporate JavascriptExecutor into my Page Object Model since some of the portions of the website I picked isn't functioning when clicking on tag. Currently this is how I my code set up in the PageObject class (my superclass for my Page-Object Model):

public class PageObject {
    protected Driver driver;
    public Actions act;
    public JavascriptExecutor js = (JavascriptExecutor) this.driver;
    PageObject(Driver driver){
        this.driver = driver;
        PageFactory.initElements(driver, this);
        this.act = new Actions(driver);
    }
}

This is the layout for the Driver class (which implements the WebDriver):

public class Driver implements WebDriver {
public WebDriver driver;
String browserName;
public JavascriptExecutor js;
public Driver(String browserName) {
    this.browserName = browserName;
    if (browserName.equalsIgnoreCase("chrome")) {
        System.setProperty("webdriver.chrome.driver", "./resources/webdrivers/chromedriver_win32/chromedriver.exe");
        this.driver = new ChromeDriver();
        this.js = (JavascriptExecutor) this.driver;
    }
    // Below are other if conditions for different browsers.

Currently, I'm getting a NullpointerException with js, but I know if I initialize js inside the PageObject constructor, I get hit with a ClassCastException. (I have these classes set up in a Maven Project.) I've looked around online and this doesn't appear to be a common topic that gets asked and right now, I'm completely stumped on how to solve this or if it's even possible. Has anyone else encountered this situation?

READ ALSO
Notification in background

Notification in background

When I open the app and send notification from the FireBase console , the onMessageReceived works fineThe app has its small icon , Notification sound ,etc

62
How to display cards in a Card Game in Java and have them clickable for selection?

How to display cards in a Card Game in Java and have them clickable for selection?

I am programming a game of cards in Java, and everything is going well, but I have come up with a problem regarding the user interfaceThere are 4 players (1 Human 3 AI) and 54 cards

51
polynomial roots in finite fields java or c++ library

polynomial roots in finite fields java or c++ library

Is there any library, java or c++, for working on polynomials in finite fields, for example finding the roots of a polynomial in a finite field? The finite field can be Zp and p may be a very large prime number

47
Java 8 does not wait for ffmpeg process output buffer read completion

Java 8 does not wait for ffmpeg process output buffer read completion

We need to create multiple clips from video, to do so we are using ProcessBuilder to create a new processes, Please fine code below

78