0

Im trying to automate a page and i wish to click the play button of a video. the video dosent has an Id so im using xPath.

I have more than 1 movie and i noticed that in the second movie the xPath of the overlay button changes (in result selenium cant find the button).

i looked a bit and found out it is wrapped with Videogular (video player).

My question is how to click that overlay play button. Im assuming it needs to be with a javascript execute command.

This is what i tried and didnt work :

js .executeScript("document.getElementByxPath(\"//*[@id=\"cdk-accordion- 
child-5\"]/div/app-sensors-video/app-cognata-video/vg-player/vg-overlay-play/div\").play()");

Which gave me nullpointerexception

public class TestClass {

    private WebDriver driver;
    private String baseUrl;
    LoginPageFactory loginPage;
    DashboardPageFactory dashboard;
    ViewSummaryPageFactory viewSummary;
    SimulationAnalysisPageFactory simulationAnalysis;
    JavascriptExecutor js = (JavascriptExecutor) driver;

    @BeforeClass
    public void setup() {

        driver = new ChromeDriver();
        baseUrl = "*****";
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.manage().window().maximize();
        driver.get(baseUrl);

        loginPage = new LoginPageFactory(driver);
        dashboard = new DashboardPageFactory(driver);
        viewSummary = new ViewSummaryPageFactory(driver);
        simulationAnalysis = new SimulationAnalysisPageFactory(driver);
    }


    @Test
    public void test() throws Exception {
        loginPage = new LoginPageFactory(driver);
        loginPage.insertUserName("foresight");
        loginPage.insertPassword("fs2018");
        loginPage.clickSubmit();
        int size = dashboard.listSize();
        for (int i=2; i<size; i++) {
            WebElement currentScenario = dashboard.createScenariosList(i);
            currentScenario.click();
            Thread.sleep(2000);
            dashboard.clickSummary();
            viewSummary.clickSimulationAnalysisPage();
            Thread.sleep(5000);
            js.executeScript("document.getElementByxPath(\"//*[@id=\"cdk-accordion-child-5\"]/div/app-sensors-video/app-cognata-video/vg-player/vg-overlay-play/div\").play()");
            String percentage = "0";
            while (percentage != "100%")  {
                WebElement elm = driver.findElement(By.xpath("//*[@id=\"cdk-accordion-child-0\"]/div/app-sensors-video/app-cognata-video/vg-player/vg-scrub-bar/div"));
                percentage  = (String) elm.getAttribute("aria-valuenow");
                if (percentage.equals("100%")) {
                    break;
                }
            }
            if (i != size) {
                dashboard.clickDashboardTab();
            }
            else {
                System.out.println("Test Completed");
            }
        }

    }

}

The Error :

java.lang.NullPointerException at test.TestClass.test(TestClass.java:55) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) at org.testng.internal.Invoker.invokeMethod(Invoker.java:580) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:988) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.privateRun(TestRunner.java:648) at org.testng.TestRunner.run(TestRunner.java:505) at org.testng.SuiteRunner.runTest(SuiteRunner.java:455) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415) at org.testng.SuiteRunner.run(SuiteRunner.java:364) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208) at org.testng.TestNG.runSuitesLocally(TestNG.java:1137) at org.testng.TestNG.runSuites(TestNG.java:1049) at org.testng.TestNG.run(TestNG.java:1017) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

Udi
  • 67
  • 8
  • null pointer should not be because of incorrect xpath. There is some other issue here. Can you share your whole code with driver call? – Helping Hands May 21 '18 at 15:30
  • Edited my post. – Udi May 21 '18 at 15:43
  • Did you debug code? at which line it gives you null pointer. can you share stacktrace? – Helping Hands May 21 '18 at 15:53
  • Hi, sorry for the late response (i was sick). i dont know why did you guys think i didnt try to debug it... well i did. it fails on the line of the java script executer (js.executeScript......) and i have added the full exception to the post – Udi May 27 '18 at 10:36

0 Answers0