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.

TypeError: Object required when trying to set variable

qafeverqafever Members
edited November -1 in Sahi - Open Source
I have a script where I set the value of a textbox, then try to retrieve the value and assign it to a variable. When I try to run the script from the Sahi controller's playback tab, I get the following error:

Error loading script. Firefox may point to the exact line. TypeError: Object required
No trace available


Here is a snippet...
for (var i = 0; i < 17; i++) {
    _keyPress(document.getElementById('LoginControlMain1_txtUserID'), 'x');
    _keyPress(document.getElementById('LoginControlMain1_txtUserID'), 'y');
    _keyPress(document.getElementById('LoginControlMain1_txtUserID'), 'z');
    _log("in loop:  " + document.getElementById('LoginControlMain1_txtUserID').value, "custom4");
}
_assertNotNull(document.getElementById('LoginControlMain1_txtUserID'));  // Returns true
_assertNotNull(document.getElementById('LoginControlMain1_txtUserID').value); // Returns true
var $uid015 = document.getElementById('LoginControlMain1_txtUserID').value; // Script fails at this line if active
What's odd is that this code runs perfectly fine on the record tab, using the Test --> button. Also, the rest of the script will run fine on the playback tab if I comment out the variable assignment. I placed the assertions in to verify that the object was there, and they return true. Also, the _log() statement within the loop references the same object, and works properly...so I'm a bit baffled. I've tried a ton of different methods of getting the value. I've even tried using _call() and _eval() - all with the same result.

Anyone have any ideas?

Thanks in advance...

Comments

  • Have you tried using this instead of the DOM:

    http://sahi.co.in/w/_byid
  • narayannarayan Administrators
    var $uid015 = document.getElementById('LoginControlMain1_txtUserID').value;
    is incorrect because it sets a page dependent variable directly.
    Use
    var $uid015 = null;
    _set($uid015, document.getElementById('LoginControlMain1_txtUserID').value);
    
    or better still:
    var $uid015 = null;
    _set($uid015, _byId('LoginControlMain1_txtUserID').value);
    
  • qafeverqafever Members
    Thanks Narayan. That did the trick. I wasn't aware of the _set() function...thanks for pointing that out.
Sign In or Register to comment.