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.

Error if checkbox is checked when doing verification of it

SadanaSadana Members
edited November 2013 in Sahi - Open Source
Hi!

I'm having again interesting problem. I'm using Sahi Java-version and web application is using Angular framework. I should check if the checkbox is checked or no and then do something based on that information.

Here's part of the element list of the web application when checkbox is not checked.
<label class="switch" ng-class="{'on': ngModel ==1}">
"✓"
<input type="checkbox" hidden ng-true-value="1" ng-model="ngModel" class="ng-valid ng-dirty">
</label>

If the checkbox is checked then label class name will be "switch on".

I have tried two different way to handle the checking.

The first version is:
if(browser.label("✓").near(browser.heading6("Title")).fetch("className").equals("switch"))
{
	//Do something fun here.
}

The second version is:
if(!browser.checkbox("on").near(browser.heading6("Title")).checked())
{
	//Do something fun here.
}

Those codes works fine as long as the checkbox doesn't meet the conditions. But when it happens, then I'll get "TypeError: _sahi.checkbox(...) is undefined" or something like that.

I have been trying to use try-catch, but it will slow down the code too much. I would like to see faster solution.

Best Answer

  • In javascript version, when it dint worked in If statement, we used
    _set($returnvalue, _checkbox("").checked)
    if($returnvalue)
    {}

    I am not sure if this info will help you.


    Regards,
    Bhavitha

Answers

  • I have to try that trick if I'm facing the same problem again.

    Now I was able to solve the problem after developer made some change to one nearby area.

    With that change I was able to do the following check and it doesn't fail if the conditions are met.
    if(browser.label("✓").in(browser.parentNode(browser.div("ID of div"))).fetch("className").equals("switch"))
    {
              //Do something fun here.
    }
    
Sign In or Register to comment.