18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

split() method not returning an array?

dasspunkdasspunk Members
edited November -1 in Sahi - Open Source
I'm trying to use the split() method to create an array and then pass that to _datadrive() but it's failing with:

Logging exception:
second argument to Function.prototype.apply must be an array

Here's my script...
$someText = "!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>?1234567890-=qwertyuiop[]asdfghjkl\;'zxcvbnm,.";

$data2 = $someText.split("");

_dataDrive(createUnit, $data2);

What am I doing wrong?

Comments

  • To clarify, the problem seems to be split() is returning a string and not an array, which rightly causes _dataDrive to fail as it requires an array.

    From my example above, split is returning the following string (via _alert):
    _alert(["!","@,#","$","%","^","&","*","(",")","_","+","Q","W","E","R","T","Y","U","I","O","P","{","}","|","A","S","D","F","G","H","J","K","L",":","\"","Z","X","C","V","B","N","M","<",">","?","1","2","3","4","5","6","7","8","9","0","-","=","q","w","e","r","t","y","u","i","o","p","[","]","a","s","d","f","g","h","j","k","l",";","'","z","x","c","v","b","n","m",",","."]);

    So, how can I get split()
  • Woops... to finish:

    How can I get split() to return an array? Am I missing something?

    Thanks,
    Brian
  • Wait! This is also not working with straight javascript... must be something I'm doing wrong.

    Nevermind :)

    B
  • Wait again! :)

    Okay, I was doing this right, I just got turned around on it. This *should* work but does not...
    $someText = "some text";
    var $data2 = [];
    $data2 = $someText.split("");
    
    _alert($data2[2]); // alerts "0"
    _dataDrive(createUnit, $data2); // exception...
    

    But it fails with the following:

    Logging exception:
    second argument to Function.prototype.apply must be an array
  • narayannarayan Administrators
    The $data2 should be a 2 dimensional array. It is a 1 dimensional array right now.
  • Ahhh... I should have seen that. Thanks Narayan!
Sign In or Register to comment.