The jwplayer getDuration function functions correctly in the Chrome console, but it encounters issues when used in C# alongside IJavaScript

I am encountering an issue with the getDuration command in jwplayers. I suspect that it might be related to a translation problem between C#'s javascript executor. Any help or insights are greatly appreciated.

Here is the problematic C# code:

IJavaScriptExecutor executor = ( IJavaScriptExecutor )Driver;
                    executor.ExecuteScript( "jwplayer().seek(jwPlayer().getDuration());", "" );

And here is the working Javascript code that functions properly in Chrome Console:

jwplayer().seek(jwPlayer().getDuration())

The above code executes as expected.

executor.ExecuteScript( "jwplayer().seek(45);", "" );

However, when running this next piece of code, it fails:

executor.ExecuteScript( "jwplayer().getDuration();", "" );

Upon execution, I encounter the following error message:

unknown error: Runtime.evaluate threw exception: TypeError: Cannot read property 'click' of null

(Session info: chrome=35.0.1916.153) (Driver info: chromedriver=2.10.267521,platform=Windows NT 6.1 SP1 x86_64)

Answer №1

It seems there may be an issue with how the executor interprets and returns the data.

I personally encountered a problem while attempting to retrieve the time duration in Jwplayer. I discovered that jwplayer().getDuration functions correctly only when used within specific events like onReady, onPlay, and onTime. If you try to access it outside of these events before the player is ready, it won't return any value.

To better understand this behavior, I created four instances of Jwplayer, some with events and some without.

You can observe this behavior here on

JSFiddle - http://jsfiddle.net/hiteshbhilai2010/6YyXH/20/

Below is the same code as used in JSFiddle:

jwplayer('player').setup({

            file: 'http://video-js.zencoder.com/oceans-clip.mp4',
            primary:'html5',
            stretching: 'exactfit',         
            autostart: true,

        });     

jwplayer('player2').setup({

            file: 'http://video-js.zencoder.com/oceans-clip.mp4',
            primary:'html5',
            stretching: 'exactfit',         
            autostart: true,

        }); 
jwplayer('player3').setup({

            file: 'http://video-js.zencoder.com/oceans-clip.mp4',
            primary:'html5',
            stretching: 'exactfit',         
            autostart: true,

        }); 
jwplayer('player4').setup({

            file: 'http://video-js.zencoder.com/oceans-clip.mp4',
            primary:'html5',
            stretching: 'exactfit',         
            autostart: true,

        });
var time1  = jwplayer('player').getDuration();
$("#player_time1").text(time1);//won't display anything

jwplayer('player2').onReady(function(){
var time2  = jwplayer('player2').getDuration();
$("#player_time2").text(time2);//will show duration as -1

});

jwplayer('player3').onPlay(function(){
var time3  = jwplayer('player3').getDuration();
$("#player_time3").text(time3);//will show duration as -1
// but clicking play and pause will display the correct time
});

jwplayer('player4').onTime(function(){

var time4  = jwplayer('player4').getDuration();
 var time45 = jwplayer('player4').getPosition()
$("#player_time4").text(time4);//it works 
    $("#player_time45").text(time45);//it works 
});

I hope this information proves to be helpful :)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What steps should I take to convert this from a string to HTML format?

I recently encountered an issue where my code was being converted into a string instead of the HTML output I intended to achieve. My main query is how can I convert this into innerHTML before it gets converted? Is there any way to accomplish this task if ...

Error: The current ChromeDriver version does not support Chrome version 91. The browser is running on version 91.0.4472.77, which is not compatible

Encountering an error when trying to run the script. Unable to create session: ChromeDriver version is only compatible with Chrome version 89 Current browser version is 91.0.4472.77 ...

Anticipated a response in the form of an object, however, a string was delivered instead

After recently updating to v14 of discordjs, I've been encountering numerous errors, including the one below. It seems a lot has changed since my last coding session, and I'm a bit unsure about what modifications are needed to ensure this ping sl ...

Leveraging the power of Javascript/jQuery to manipulate form

On my website, I have implemented a form that requires a customized response for certain zip codes. To achieve this, I am developing a code that validates the first 3 digits of the entered zip code against a predefined array in my system. Although the code ...

How can we access state data in a Vuex component once it is mounted?

My goal is to initialize a Quill.js editor instance in a Vue component once it is loaded using the mounted() hook. However, I am facing an issue where I need to set the Quill's content using Quill.setContents() within the same mounted() hook with data ...

Bootbox Dialog Form

Looking to implement a functionality where a Bootbox dialog pops up with an "OK" button. Upon clicking the "OK" button, it should initiate a POST request, sending back the ID of the message to acknowledge that the user has read it. The Bootbox dialog fun ...

Show spinner until the web page finishes loading completely

Could anyone guide me on how to display Ring.html for a brief moment until About.html finishes loading completely? I need the Ring.html page to vanish once About.html is fully loaded. As a beginner in web development, I would greatly appreciate your assist ...

Removing a Dynamic Element in ReactJS

--CustomFieldSection.js-- import React, { Component } from 'react'; import CustomField from './CustomField.js'; class CustomFieldSection extends Component{ constructor(props){ super(props); this.stat ...

Guide to adding customized CSS and JavaScript to a specific CMS page on Magento

I'm trying to incorporate a lightbox for video playback on a specific page of my CMS. I've placed my CSS file in JS/MY THEME/JQUERY/PLUGIN/VENOBOX/CSS/myfile.css and the JS files in JS/MY THEME/jquery/plugins/venobox/js/myfile.js, but it doesn&ap ...

A guide on testing mouse clientY in React using JEST for effective testing

useEffect(() => { const mouseHandler = (event: MouseEvent) => { menuData.forEach((element) => { if (element.hasActiveDropdown && event.clientY > 50) { handleCloseDropDown(); // handleDropDown('0') ...

The compatibility between Node JS and Vue JS front-end seems to be glitchy and

I am currently developing a Node JS backend application and Vue JS front-end. In order to authenticate users, I need to implement sessions in the API. For my backend server, I am using the following components: express (4.18.2) express-session (1.17.3) c ...

Using Javascript to Pass Variables to Ajax with getElementById

Struggling to figure out how to effectively pass a Javascript Variable to Ajax and then post it to PHP? While both the Javascript and PHP code are functioning as expected, the challenge lies in transferring the Javascript Variable to Ajax for subsequent ...

Setting a variable equal to user input

When using a jQuery script, the elements for the details are dynamically created inside a jQuery function. However, there seems to be an issue with assigning the value from the variable "startLocation" to the input "detail_startLocation[]". Only the firs ...

Tips on incorporating jQuery cross-domain functionality

Attempting to retrieve and display the firstName data from this URL: http://www.w3schools.com/jquery/demo_ajax_json.js, as part of a test for another project. Encountered the error message: Origin null is not allowed by Access-Control-Allow-Origin, prompt ...

Issue with rendering in React Router

I've been having trouble with React Router in my code. I know that there have been changes from Switch to Routes in React Router Dom v6, but even after making the adjustment, my program just displays a blank screen. Can anyone help me resolve this iss ...

Display all items on page load using ng-repeat checkboxes in AngularJS filter

I have encountered a problem with filtering checkboxes in my code. I want all products to load on the page initially, and then when I check multiple checkboxes within technologyArray and/or technologyArray2, the products that match the checkbox name should ...

Choose not to alter the display value during keyup and keydown events, while still triggering the change event

$(function(){ $(".cls_user_details select").keyup(function(){ $(".cls_user_details select").val("Profile"); }) }) <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="cls_user_setti ...

unable to update database using jquery ajax

Hello everyone, this is my first time posting on Stackoverflow! I am facing an issue while trying to run an "Insert" query using Jquery's $.ajax function. Upon checking the network tab on Chrome Dev Tools, it seems like my file is being loaded but th ...

Recover Checkmark Status from Data

Currently, I am storing form data in json format and encountering an issue when trying to load values from a previously created json file. The plain old JavaScript function provided below successfully loads values into a form from a file, effectively resto ...

Reproducing a table row

Here is the table structure I am working with: <table id="customFields" class="table table-bordered table-hover additionalMargin alignment"> <thead> <tr> <th colspan="2"></th> <th>Some Title</ ...