Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

findIndex() method issue with internet explorer

Tags:

I am doing some tests with differents browsers using the Selenium::Remote::Driver module.

I would like to check if I find some item in my web site list, list from a framework JavaScript (which creates grids). For this case I have to use JavaScript snippet allowed by Selenium::Remote::Driver.

I wrote the following code

$script = q{        var paramProgramName = arguments[0];        var list  = $('#c-list').dxList('instance');       var items = list.option('items');       var index = items.findIndex(function(el){ return el.name == paramProgramName; });        list.selectItem(index);        return ; };  $driver->execute_script($script, $programName); 

It works fine with Chrome and Firefox but not with Internet Explorer because the findIndex method is only supported by version 12 and following. For some reason I have to use version 11.

What can I do differently to get an index from every browser?

like image 656
Chaoui05 Avatar asked Jun 08 '16 09:06

Chaoui05


People also ask

Does findIndex work in IE?

It works fine with Chrome and Firefox but not with Internet Explorer because the findIndex method is only supported by version 12 and following.

What is the difference between indexOf and findIndex in Javascript?

findIndex - Returns the index of the first element in the array where predicate is true, and -1 otherwise. indexOf - Returns the index of the first occurrence of a value in an array.


1 Answers

So my question is how can i do differently to get my index for every browser ?

You have at least three options:

  1. Shim Array#findIndex; MDN has a shim/polyfill you can use.

  2. Use something else that IE11 has, such as Array#some (which even IE9 has):

    var index = -1; items.some(function(el, i) {     if (el.name == paramProgramName) {         index = i;         return true;     } }); 
  3. Use something else that even IE8 has, such as for:

    var index = -1; for (var i = 0; i < items.length; ++i) {     if (items[i].name == paramProgramName) {         index = i;         break;     } } 
like image 61
T.J. Crowder Avatar answered Sep 17 '22 14:09

T.J. Crowder