Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find control's properties #236

Closed
CheNMorD opened this issue Aug 2, 2017 · 5 comments
Closed

Find control's properties #236

CheNMorD opened this issue Aug 2, 2017 · 5 comments

Comments

@CheNMorD
Copy link

CheNMorD commented Aug 2, 2017

Hi,
I'm using appium in visual studio for testing a simple WPF application,
I'm using WindowsDriver

WindowsDriver<WindowsElement> driver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), desiredCapabilities);

I know how to enter text and how to get text from TextBox:

driver.FindElementByAccessibilityId("MyTextBox").SendKeys("123");

I wanted to know if there any way to get and set control's properties, For example: get IsChecked from CheckBox, get Background from TextBlock etc.

Thanks.

@dhapolapankaj
Copy link

You can try exporting the PageSource to an XML file and then

driver.FindElementByAccessibilityId("MyTextBox").GetAttribute("innerHTML"));

You will get clue for your Intended property or attribute values to pass as an argument in GetAttribute function from this exported XML file.

I'm not sure if we can set value of the control by setting the value of attribute, even if we can it would not be a good idea because the background events are not triggered for some controls.

You will have to utilize the exposed methods like Click(), SendKeys() etc. to set the values.

Regards
PD

@CheNMorD
Copy link
Author

CheNMorD commented Aug 9, 2017

@dhapolapankaj
Thanks for your answer,
I guess that your solution is for a web app,
but like I said i'm testing a desktop app and the ui of this app
is written in XAML (using WPF) , is there a way to get properties from controls in my desktop app?

Thanks.

@dhapolapankaj
Copy link

dhapolapankaj commented Aug 15, 2017

:) I would still insist you to export the PageSource

try below code

System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(driver.PageSource.ToString());
System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(@"c:\App_To_XML.xml", new System.Text.UnicodeEncoding());
writer.Formatting = System.Xml.Formatting.Indented;
doc.WriteContentTo(writer);

See if you have got the "App_To_XML.xml" file generated

Let us know if you are enlightened.

@timotiusmargo
Copy link
Contributor

timotiusmargo commented Aug 17, 2017

Hi @CheNMorD,

Typically, I would use Selected property of the element to see if a Checkbox is checked. And as @dhapolapankaj mentioned, you need to perform user interaction through touch, click, or keyboard input just as what the user would need to do on your application. Below is a snippet of interaction with a XAML CheckBox control in a UWP app taken from https://github.com/Microsoft/WinAppDriver/blob/v1.0-RC/Tests/UWPControls/CheckBox.cs#L97

var originalState = checkBoxElement1.Selected;
checkBoxElement1.Click();
Assert.AreNotEqual(originalState, checkBoxElement1.Selected);
checkBoxElement1.Click();
Assert.AreEqual(originalState, checkBoxElement1.Selected);

For any other element properties shown on inspect.exe, you can use the GetAttribute API. This feature is recently available in v1.0-RC. You can find an example of getting various attributes/properties on the following sample test:
https://github.com/Microsoft/WinAppDriver/blob/v1.0-RC/Tests/WebDriverAPI/ElementAttribute.cs#L38

Note that element properties that are not exposed to the accessibility layer such as background color and font, cannot be retrieved by Windows Application Driver nor inspect.exe.

@MarcoDeJesus
Copy link

As described by @bharathp666 in #590 we can check the whole xml document through driver.PageSource.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants