I have a problem regarding getting and setting the state of a checkbox.
This is needed conditionally, so I have to do it in User Code anyway.
I found this:
https://www.ranorex.com/forum/how-to-ch ... t6087.html
I tried to use the code from there, but I have some problems with it.
My code:
Code: Select all
public static void SetCheckboxState(RepoItemInfo webelementInfo_checkbox, string checkboxState)
{
// Instantiate repository
MyRepo repo = MyRepo.Instance;
//create the checkbox from the repository
Ranorex.CheckBox chkbox = repo.Projects.Workflow.ET.Checkbox_1;
//Show the checked state
var test = chkbox.Checked;
}
Cannot convert type 'Ranorex.WebElement' to 'Ranorex.CheckBox'
What am I doing wrong?
Usually I instantiate my Elements with
Code: Select all
WebElement checkbox = webelementInfo_checkbox.CreateAdapter<WebElement>(true);
The checked attribute is not there when unchecked, and appears when checked, like here: https://www.w3schools.com/tags/att_checked.asp
Regarding the DOM, the checkbox looks like the following:
unchecked:
Code: Select all
<custom-checkbox><span>Checkbox 1</span></custom-checkbox>
Code: Select all
<custom-checkbox checked><span>Checkbox 1</span></custom-checkbox>
Code: Select all
body//div/tag[@tagname='custom-checkbox']/span[@innertext='Checkbox 1']/ancestor::tag[@tagname='custom-checkbox']
BR
mrt