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

I encountered difficulty in assigning a JSON response to a variable, both with and without using JSON.parse()

I'm in the process of creating a website that, among other things (and crucially for this particular issue), stores your current location data in a variable by fetching it from the ipinfo API (https://ipinfo.io/json) After encountering the problem of ...

How can I dynamically display Material-UI's <MenuItem/> within a <DropDownMenu/> using ReactJS?

In my ReactJS + Material-UI project, I am working with an array named colors that contains different color strings such as "white", "blue", and "green. My goal is to render each color string as a <MenuItem/> within a <DropDownMenu/> component ( ...

What are the steps to integrating JavaScript autocomplete into a website?

I am relatively new to the world of programming, particularly when it comes to JavaScript/jQuery. I have been searching online for a solution to enable autocomplete in my search feature, but despite trying various approaches found on the internet, I have y ...

Can Comet be implemented without utilizing PrototypeJs?

Can Comet be implemented without utilizing PrototypeJs? ...

Having issues with my jQuery getJSON request. It's returning an empty response even though

I have been struggling to find a solution to this particular issue with no luck... Here is the jQuery getJSON request that I am working on: $.getJSON("http://localhost:8080/context/json/removeEntity.html", { contentId : 1, entIndex : entityIndex ...

Tips for retrieving console data in VueJS Data

Is there a way to review data from a form component in the console without vue taking any action? I need to receive external data and fill in the fields accordingly. I attempted to set a value using document.getElementsByName("nfe.codigo")[0].value = "000 ...

AngularJS - ng-repeat not updating when property array changes

I have a loop in my HTML using ng-repeat: <div class="row"> <div ng-repeat="item in model.painel track by item.codigoIncidente"> <strong>{{item.restante.horaMinutoSegundo}}</strong> </div> </div> In ...

Learn the process of converting Null values to empty strings within a chain of functions when manipulating a database

Currently, I am utilizing the lodash library and have the following code in place: data: _(responseData.data) .pick(['title', 'layout', 'slug', 'author', 'seo', 'css', 'js']) ...

Organizing various elements into separate divs with just one ajax request

I recently encountered an issue with my project involving an ajax call that was functioning correctly. $.get( 'accNoRealMovs1.jsp', {mode:"0"}, function(responseText){ $('#divAccMovementNR').html(responseTe ...

An error has been encountered in the main thread: java.lang.IllegalStateException - The driver executable required for Selenium in Java is missing

Oh no! An error has occurred: Exception in thread "main" java.lang.IllegalStateException: The driver executable must exist Here are the code trials that led to this issue: import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.C ...

What steps can be taken to ensure that the popover div remains visible when clicking inside it in a "dismissible popover" using Twitter Bootstrap with the data-trigger attribute set to "

I am struggling with a dismissible popover that contains a text box. When I click inside the text box to type, it disappears due to the "data-trigger="focus". Is there a way for the div not to disappear when clicked inside intelligently? Here is the releva ...

Building a C# .NET WebForms application using the ajaxcontroltoolkit.net library to incorporate AsyncFileUpload functionality while triggering the OnClientUploadError event server-side

Discussing a specific control, the AjaxControlToolKit AsyncFileUpload, in the context of maintaining a legacy .NET webforms (codebehind) application where server-side errors need to be displayed. Unable to simply set a label in the code behind due to the ...

What is preventing the use of this promise syntax for sending expressions?

Typically, when using Promise syntax, the following code snippets will result in the same outcome: // This is Syntax A - it works properly getUser(id).then((user) => console.log(user) // Syntax B - also works fine getUser(id).then(console.log) However ...

Executing the callback function passed as a prop

I'm a bit confused about how to call a callback function in an element's prop. Let's say I have a button here: <Button onPress={() => { loadMore()}} title="Load More" backgroundColor='#0A55C4' /> I am wondering wh ...

When utilizing jQuery, I implemented this code but it does not display anything. I am unsure of the error within the code

When using jQuery, I implemented the following code snippet but it doesn't display anything. What could be causing this issue? // $.ajax({ // URL:"https://dog.ceo/api/breeds/image/random", // method:"GET", // ...

React Native - Implementing asynchronous array filtering using async/await

In my code, there is a filtering method implemented as follows: _filterItems(items) { return items.filter(async item => { let isTrue = await AsyncStorage.getItem('key'); return isTrue; }) } However, when calling the method this._ ...

Tips for establishing a universal onkeydown listener for all frames within a webpage?

Working with a complex legacy multi-frame webpage that needs to be compatible with IE-11 and responsive to hotkey events has brought up some challenges. It appears I can't simply declare a JavaScript method in the parent page. Rather, it seems that e ...

Solving synchronization issues when updating and selecting MySql data in a Node.js environment with concurrent multiple requests

Currently, I'm using expressJS with an endpoint that connects to a MYSQL database. This endpoint executes a query to retrieve data and assigns the first result to a user by updating a specific field with the user ID. The rule is that each row can onl ...

What is the reason for node executing both of these handlers on the server?

My node app is set up with two handlers, one for requests to the root URL and another for the slug. However, when I visit the root or slug URLs, the app crashes and I receive this error: url is pointing to root url has a slug throw err; // Rethrow non-MySQ ...

What is the best way to trigger an event from a child component to a parent component in

parent.component.ts public test(){ //some code..... } parent.component.html <app-child (eventfire)="test($event)"></app-child> In this scenario, the child component button is displayed within the parent component. However, there i ...