Ask a Question

How to find the status of checkboxes on webpage window

sarya
Frequent Contributor

How to find the status of checkboxes on webpage window

Hi,



I am trying to verify the status of the checkboxes marked under options R,C,F as seen in screenshot . I am able to click on that with this code but somehow the status verification is not working. I tried CellObj.status and CellObj.checked but for both of them it is not able to find status and chekced property.What can I use to verify the checkbox status whether it is checked or not. Checbox enables property will not work as the checkbox under C and F are always enabled,i need to check whether they are checked or unchecked.



{

page3 = iexplore.Page("http://" + servername + ":" + port + "/" + r2wcontext + "/user.do*");

document = page3.document;

page3.NativeWebObject.Find("title","UserRead","A").Click();

all2 = document.all;

var cellText = "/UserRead";

var cellObj = GetNextCell(all2, cellText);

if (cellObj.status == "False")   //This is not working.

Log.Message("The content access for member is saved correctly","",pmNormal,Attr);

else

Log.Error("There is some error","",pmNormal,Attr);

}




function GetNextCell(allObj, cellText)

{

var obj = allObj.FindChild("outerText", cellText);

var nativeCell = obj.parentNode.cells.item(2);

return allObj.FindChild("uniqueID", nativeCell.uniqueID);

}



Thanks.


GetNextCell(allObj, cellText){ obj = allObj.FindChild("outerText", cellText); nativeCell = obj.parentNode.cells.item(2); allObj.FindChild("uniqueID", nativeCell.uniqueID);}Thanks.
13 REPLIES 13
YMinaev
Staff

Hi,



You're using the status property incorrectly (comparing it with a string whose value is "False"). Look at this property in the Object Browser and check what values it has.
------
Yuri
TestComplete Customer Care Engineer

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
sarya
Frequent Contributor

Hi Jared,



I checked the value for property "Status" and it has value as "False" when unchecked .Can you please tell me what else can I use to verify the checkbox state.



Thanks,

Sumedha
YMinaev
Staff

Hi,



It is a boolean value, not a string. You need to use the boolean constant false in your code, not a string with the value "False".
------
Yuri
TestComplete Customer Care Engineer

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
sarya
Frequent Contributor

Hi Jared,



If I see the property checked for the checkbox in this way as below,it shows the value as True .

"page3.document.all.Item("access67Read").checked"



But if I use it using cellObj  like cellObj.checked ,it gives the error :Unable to find the object checked. So it is not recognising the cellObj.checked statement.But if I do this action as cellObj.Click ,it checks the checkbox correctly.

var cellObj = GetNextCell4Read(all2, cellText);





Thanks,

Sumedha


AlexanderM
Staff


Hi,





Most probably, you're trying to access the checked property which belongs to a wrong object. You need to use the check box, not the cell.
-----

Alexander
Customer Care Manager
sarya
Frequent Contributor

Hi Alex,



var cellObj = GetNextCell4Read(all2, cellText);



cellObj.click() works fine.It clicks the correct checkbox ,then why is it not able to verify the checked property of the same checkbox.



Thanks,

Sumedha
YMinaev
Staff

Hi,



The target check box is inside the cell. Try clicking on the cell manually - the check box will change its state since you hit it when clicking. But the cell object knows nothing about the check box state, you need to ask the check box about it directly.
------
Yuri
TestComplete Customer Care Engineer

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
sarya
Frequent Contributor

Hi Jared,



As per your reply:-

" The target check box is inside the cell. Try clicking on the cell manually - the check box will change its state since you hit it when clicking. But the cell object knows nothing about the check box state, you need to ask the check box about it directly."



I already have attached the screenshot.I am still not able to understand as how to check the state of the checkbox.Can you please tell me how to verify it and what property should be used to verify ?



Thanks,

Sumedha
YMinaev
Staff

Hi,



Use code like this:

...

var checkbox = // Obtain your check box (the check box, not the cell in which it is located)



if(checkbox.state)

{

//checked

}

else

{

//unchecked

}

...

------
Yuri
TestComplete Customer Care Engineer

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
cancel
Showing results for 
Search instead for 
Did you mean: