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?
It works fine with Chrome and Firefox but not with Internet Explorer because the findIndex method is only supported by version 12 and following.
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.
So my question is how can i do differently to get my index for every browser ?
You have at least three options:
Shim Array#findIndex
; MDN has a shim/polyfill you can use.
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; } });
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; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With