-
Notifications
You must be signed in to change notification settings - Fork 125
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
How to add support for element attributes other than ClassName, Name, AutomationId? #19
Comments
In Winium.Desktop you can try using XPath to locate elements based on attribute values. |
Hi @NickAb .I am doing automation of Windows10 mobile application using Winium.Storeapss.Can we use FindElementByXpath stratergy to find elements in Winium.Storeapps? |
Winium.StoreApps uses See relevant code https://github.com/2gis/Winium.StoreApps/blob/master/Winium/Winium.StoreApps.InnerServer/Commands/PageSourceCommand.cs#L39-L59 for reference on attributes. You can try using Winium.StoreApps.Inspector to get idea of XML tree that Winium uses internally. |
Hi @NickAb . Finding elements using Xpath is key point in our framework development.I am stuck here. |
Hi @NickAb . It seems to be issue with Winium.StoreApps.InnerServer.But then how can I run xpath query from Winium Inspector against the same application instrumented using Winium.StoreApps.InnerServer version 1.6.2? I am using Windows 8.1 Pro desktop machine and trying to automate Windows 10 mobile application on Windows 10 Simulator |
@Pranodayd Sorry, I misled you. Winium.StoreApps does not support XPath as a locator strategy at the moment, because Store Apps framework had no classes needed to implement it. XPath only supported on Winium.Desktop. |
Hi @NickAb . |
I do not think that there is easy way to add fast XPath support. By it can be hacked by modifying GetPageSource command (by registering all the elements and returning their ids) and evaluating xpath on Driver.exe side (not on the phone) and then requesting element by id from attribute of element obtained during evaluation of XPath. |
@NickAb I didn't get you exactly.Can you please explain it in more detail? We have Appium framework implemented for Android and IOS application,now we want to extend this framework to Windows 10 application.This can be only possible by using a tool which is based on Selenium-Webdriver like Winium.We are really looking to Winium as our potential Windows 10 mobile application tool. We have used Xpaths extensively for element identifications as our developers have not set unique Ids for UI controls and most of our UI controls are developed using custom classes derived from native SDK calsses.Hence we don't really have an option other than Xpath. |
The preferred way of locating elements in Winium is using Automation Properties, like AutomationId, which are add to elements by developers to improve test-ability. This strategy should be preferred on other platforms too, tests will be less fragile due to UI changes. |
Hi @NickAb . |
@NickAb .I now understood option you gave me in following reply: You mean to say here that,Driver will run Xpath and return ID of filtered element and then we can use FindElementById() and pass it the ID which we have got from previous command. But again in order this to work we need to have Unique Ids for all our controls,which is currently not the case. |
I was not talking about AutomationId of the element, but rather a concept of id used by selenium. When element is found, selenium assigned internal id to this element. This id is used to identify the element you want to get text from, send keys to, etc. One can modify GetPageSource implementation on Inner Server side to register each element that is getting printed in page source and append its internal id (generated at runtime by Winium) to page source as attribute on the element. This is described in 2gis/Winium.Mobile#29 (comment) |
Hi @NickAb . |
Hi @NickAb . |
Yes, it can be done kind of like you wrote in last message, but it all can be hidden in FindElementByXPath on Driver side. Anyway, such implementation will be very slow, I recommend researching a way to use other element locating strategies. In case if element does not have AutomationId we just search for element iteratively limiting our scope on each step. For example, we will first find a parent of element to be found as close as we can. Then we will find all elements of this parent that have the class we need, afterwards we will iterate them and check their value or any other identifying property. So in your case buttons = driver.find_elements_by_class('Windows.UI.Xaml.Controls.Button')
for button in buttons:
if button.text == 'OK':
button.click()
break or even shorter buttons = driver.find_elements_by_class('Windows.UI.Xaml.Controls.Button')
next(x for x in buttons if x.text=='OK').click() I used python for sample, as it is what we use, but it should be easy to translate to Java. |
@NickAb . Many thanks @NickAb for taking out time to respond to my queries. |
You can contact me at [email protected] |
Hi @NickAb . Thanks |
Assuming the element is parent.find_elements_by_class_name(DESCENDANTS_CLASS_NAME) But note that: |
Hi @NickAb I dont have any option of retrieving the element using the SIBLING relationship it has with some other element.I can manage it though if I get all child elements of certain Parent element e.g. using Parent.findElements(By.cssSelector("*")); What I can do is,I will get the list of all child elements of parent element irrespective of any class or ID and traverse this till I get the Element,relationship of which I want to take into consideration.And then I will use the List index of this element to further go and search for the desired element in the list. But I don't have any option currently to retrieve all child elements of any parent element without giving any attribute. Thanks |
Hi @NickAb |
I don't think there is any way to query siblings currently. You will have to somehow find a parent element, for example using findElementsByClassName and getting it by known index from a collection. This will let you limit the scope for the following search. So, for example in case of label and textbox being siblings you could first look for their parent. Lets assume it is stackpanel at index 5. parent = driver.find_elements_by_class_name(STACKPANEL_CLS)[5] Then you will simple find the textbox by its known index in the tree: parent.find_elements_by_class_name(TEXTBOX_CLS)[3] But this will be hard to maintain and it also will not be performant. I would suggest you to invest into testability of the app and add |
Hi @NickAb . Thanks for the reply.I got your suggestion.Will try to see if this can be of any help to me. Actually our developer is only for 1 month with us,and hence he does not want to waste time in making application testable,hence I can't ask him for anything to be done to make application testable,at least for now. Thanks. |
@Pranodayd You can do it yourself as it only requires you to edit some XAML files by adding appropriate XML attributes. You can ask developer to guide you for first time. This might be time consuming first time, but then it will be easy and save a lot of time on fixing broken tests when UI changes. I am closing this issue, because it was initially created for Winium.Desktop project. Moving discussion of Winium.Mobile XPath support to 2gis/Winium.Mobile#29. Seems that somebody repacked System.Xml.XPath as Nuget package for Silverlight apps, we should try it out and see if it will work in StoreApps project too. No definitive timeline here, will try to find some time in May to test it. |
Hi @NickAb . |
@Pranodayd XPath would not help you at the moment as it is not client side, we would need to implement an XPathNavigator based on this package and add xpath as a strategy to Winium. This will require modification of Winium.StoreApps project. But we have already used such approach in Winium.Desktop, so I think it should work out. Meanwhile the only option is to do as I have described in #19 (comment) |
How easy to add support for element attributes other than ClassName, Name, AutomationId?
Particularly I consider ControlType when all 3 above are empty.
The text was updated successfully, but these errors were encountered: