Runtime identification of type of control
Posted: Wed Apr 20, 2016 6:09 am
Hello Ranorex team,
I want to write a user code, the intention of the code is, given an rxPath and the value, the code must find the control and set the value.
the control can be a text box, combobox, list box, what not.
so I have to determine the type of the control in the runtime and invoke to according api to set the value for that control.
the rxPath looks like this,
"/form[@controlname='ApplicationFrame']/container[@caption~'^HierarchyFrame:\ Siemens\.A' and @controltypename='HierarchyFrameControl']/container[@controlname='EditorMainFrame']/?/?/container[@controlname='Siemens.Energy.Digsi.FunctionSettings.View.EditorPageFrame']/container[@controlname='Siemens.Energy.Digsi.FunctionSettings.View.SettingsView']//container[@controlname='m_DomainObjectControl']//container[@caption='Definite-T 1']/?/?/combobox[@controlname='0|0|']";
the code looks like this,
public void SetValue(string path, string value)
{
1. Accessible accessible = repo.ApplicationFrame.ModeChangeValueInfo.CreateAdapter<Accessible>(false);
2. AccessibleRole role = Accessible.FromPath(path).Role;
3. Accessible accessible1 = Accessible.FromPath(path);
4. switch(role)
5. {
6. case AccessibleRole.Text:
7. Text text = accessible1.As<Text>();
I want to find the role from the path. Then I want to create a Accessible adapter from the path.
based on the role, I would cast the Accessible adapter to the relevant adapter and do the necessary things to set the value.
The code in line 1 is not relevant to the logic of the method. But without the first line, line 2 throws an exception.
My wish is, the code has to work without the first line like this
2. AccessibleRole role = Accessible.FromPath(path).Role;
3. Accessible accessible1 = Accessible.FromPath(path);
4. switch(role)
5. {
6. case AccessibleRole.Text:
7. Text text = accessible1.As<Text>();
But it is not working so. Please advise as what is missing to make it work.
Regards,
Siva
I want to write a user code, the intention of the code is, given an rxPath and the value, the code must find the control and set the value.
the control can be a text box, combobox, list box, what not.
so I have to determine the type of the control in the runtime and invoke to according api to set the value for that control.
the rxPath looks like this,
"/form[@controlname='ApplicationFrame']/container[@caption~'^HierarchyFrame:\ Siemens\.A' and @controltypename='HierarchyFrameControl']/container[@controlname='EditorMainFrame']/?/?/container[@controlname='Siemens.Energy.Digsi.FunctionSettings.View.EditorPageFrame']/container[@controlname='Siemens.Energy.Digsi.FunctionSettings.View.SettingsView']//container[@controlname='m_DomainObjectControl']//container[@caption='Definite-T 1']/?/?/combobox[@controlname='0|0|']";
the code looks like this,
public void SetValue(string path, string value)
{
1. Accessible accessible = repo.ApplicationFrame.ModeChangeValueInfo.CreateAdapter<Accessible>(false);
2. AccessibleRole role = Accessible.FromPath(path).Role;
3. Accessible accessible1 = Accessible.FromPath(path);
4. switch(role)
5. {
6. case AccessibleRole.Text:
7. Text text = accessible1.As<Text>();
I want to find the role from the path. Then I want to create a Accessible adapter from the path.
based on the role, I would cast the Accessible adapter to the relevant adapter and do the necessary things to set the value.
The code in line 1 is not relevant to the logic of the method. But without the first line, line 2 throws an exception.
My wish is, the code has to work without the first line like this
2. AccessibleRole role = Accessible.FromPath(path).Role;
3. Accessible accessible1 = Accessible.FromPath(path);
4. switch(role)
5. {
6. case AccessibleRole.Text:
7. Text text = accessible1.As<Text>();
But it is not working so. Please advise as what is missing to make it work.
Regards,
Siva