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

Possibility to use Relative path for element finding #109

Closed
savitakul opened this issue Jun 23, 2023 · 5 comments
Closed

Possibility to use Relative path for element finding #109

savitakul opened this issue Jun 23, 2023 · 5 comments

Comments

@savitakul
Copy link

Hi,
We are checking if RobotFramework-Flaui is suitable for out test developement. Our team have around 1000+ tests in Coded UI and looking to shift to robotframework tests. We are considering the Flaui for test shift and new test development but during PoC we stuck on below issue -

Unable to locate element with Relative XPATH.
We have desktop application which has lot of pane and containers, the elements are located within these panes.
Example:
We are able to locate element with xpath: /Window[@name='XYZ']/Pane[2]/Pane[2]/ComboBox[2]

But this will be hard to maintain the XPATH, will it possible to access these elements with Relative XPATH, something like this -
//ComboBox[@name='abc'] ---> Search element anywhere on screen which is visible with given name ?

Appreciate the help!

@Nepitwin
Copy link
Member

Hi,

Xpath can be used asweel by Tree Searching usage.

Here are some of Examples --> https://github.com/GDATASoftwareAG/robotframework-flaui/blob/documentation/examples/xpaths/xpaths.robot

https://github.com/GDATASoftwareAG/robotframework-flaui/blob/documentation/examples/xpaths/

https://gdatasoftwareag.github.io/robotframework-flaui/xpath.html

You are able to search on a Combobox pattern with your example.

Properties like @name, @AutomationID or @Class can be used here. Automation ID should be used by general and can be set to most of all GUI Application to identify all gui elements directly or search for them if a pattern is generated.

Syntax with Array usage below is a way to go but for my opinion not recommended.

Hope that helps for you and you can adjust your PoC.

@savitakul
Copy link
Author

savitakul commented Jun 26, 2023

Thanks @Nepitwin for direction to look into.
I have tried the provided simillar xpath to what provided in examples, but the outcome is failure to find xpath element.

We have application which responds well to UIA2, with UIA3 we get methodnotimplemented error.

When i provide full XPATH -> TEST PASSED

Library FlaUILibrary UIA2
${XPATH_CONTAINS_AND} /Window[contains(@name,"Deposit/Loan")]/Pane[2]/Pane[1]/Edit[@name="Name:"]
[info] Slept 10 seconds
[info (+10.08s)] Slept 10 seconds
TC01 | PASS |

Prime :: Test suite for application keywords. XPath not found erro... | PASS |
1 test, 1 passed, 0 failed

When i provide relative XPATH --> TEST FAIL

${XPATH_CONTAINS_AND} /Window[contains(@name,"Deposit/Loan")]//Edit[@name="Name:"]
[FAIL (+2.36s)] FlaUiError: Element from XPath '/Window[contains(@name,"Deposit/Loan")]//Edit[@name="Name:"]' could not be found

When i debug the code, i can see the test fails to get_element()
image

Also the XPTH is verified on FlaUIInspect and it looks like this:
image

Can you please suggest your view on this?

@Nepitwin
Copy link
Member

Your xpath can be easier handled.

/Window[contains(@name,"Deposit/Loan")]/Pane[2]/Pane[1]/Edit[@name="Name:"]

Can be adjusted to

/Window[@name="Deposit/Loan"]/Pane[@AutomationID="59648"]/Pane[@AutomationID="59649"]/Edit[@AutomationID="59652"]

This usage is a direct execution by AutomationID Properties which should be static. So your test will be always successfully if not changed by any adjustment.

Your approach is intresting because you try to search an element by a given name from all subtrees.

/Window[contains(@name,"Deposit/Loan")]//Edit[@name="Name:"]

I think tree search is here searching only on the level after Window. So editbox could not be found.

But i think it should be exists something simillar on xpath like * to indicate so search to all sub elements

https://www.w3schools.com/xml/xpath_syntax.asp

/Window[contains(@name,"Deposit/Loan")]//*//Edit[@name="Name:"]

I will check if something exists like *.

Sadly i don't found any documentation for xpath usage on desktop automation since today.

It would be nice to see what can be done by these xpath usages here.

@noubar
Copy link
Contributor

noubar commented Jul 8, 2023

@savitakul Your problem is related to the issue #82
You are trying to access for example using a relative xpath like this : /Window[contains(@name,"Deposit/Loan")]//Edit[@name="Name:"]
What you should be aware of in this approach there is a linear search done by flaui to find a matching xpath and the first matching element will be taken.
This means under the window of /Window[contains(@name,"Deposit/Loan")] there is somewhere an edit element with the name = Name:
The flaui begins to search under the window"Deposit/Loan" in the list of first depth children of window if there is a matching element if not then the iterration will continue to first level children of the first child of window and so on. deeper and deeper until no element left. According to my experience every single element will be searched so there is no need to declare //*//.

The first matching element will be taken as the right element.
in your case if the test case is failing this means in the xpath tree of your app there is an edit element with name Name: ordered before your intended element. I will assume the windows"Deposit/Loan" first pane[1] has as child or grand child an edit Name: element. As @Nepitwin also suggested you should try to approach with automation ids or unique names which only and only the intended elment has it. Then there is no reason to the relative xpath to not to work.

@savitakul
Copy link
Author

Thanks @noubar will try the approach with automation ids instead. I think that will be most reliable way to handle the xpath.

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

3 participants