Winium.Desktop icon indicating copy to clipboard operation
Winium.Desktop copied to clipboard

XPath locator for Edit box is not working

Open smtripathi99 opened this issue 3 years ago • 7 comments

Hi,

I have a window application and I am trying to locate Password filed using xpath but it is not working. I tried followings:

driver.findElement(By.xpath("/[contains(@ControlType,'ControlType.Window') and contains(@Name,'Sabre Travel Network')]//[contains(@ControlType,'ControlType.Edit') and contains(@Name,'Password')]"));

driver.findElement(By.xpath("//[contains(@ClassName,'SWT_Window0') and contains(@Name,'Travel Network')]//[contains(@ControlType,'ControlType.Edit') and (@Name='Password')]"));

driver.findElement(By.xpath("//[contains(@ProcessId,'sabrered') and contains(@Name,'Travel Network')]//[contains(@ControlType,'ControlType.Edit') and (@Name='Password')]"))

smtripathi99 avatar Feb 12 '21 16:02 smtripathi99

@smtripathi99 maybe try with WADUIRecorder. You might be able to you automationid and use it as the id in winnium

image

anileapen avatar Feb 12 '21 16:02 anileapen

@anileapen ,

Please provide the URL to download WAD UIRecorder

smtripathi99 avatar Feb 12 '21 16:02 smtripathi99

I have got the source for UI Recorder https://github.com/microsoft/WinAppDriver/tree/master/Tools/UIRecorder/UIRecorder. How can I run it?

smtripathi99 avatar Feb 12 '21 22:02 smtripathi99

You can get it from https://github.com/microsoft/WinAppDriver/releases/tag/UiR_v1.0-RC Scroll down and download the .zip file. Inside the unzipped folder you will find : WinAppDriverUiRecorder.exe Just run that and open your application and move your mouse to the control . You might be able to get the automation id or name for the element. You can use this in your winium code

anileapen avatar Feb 14 '21 13:02 anileapen

Thanks i can run it now and see the xpath but code mention under C# is not working. Unable to find element comes

smtripathi99 avatar Feb 14 '21 16:02 smtripathi99

Did you try using id or name instead of xpath. From the UI recorder you can use the "automation id" as the id in your code and "Name" as the name below IWebElement element = driver.FindElement(By.Name("xxxxxx")); or IWebElement element = driver.FindElement(By.id("xxxxxx"));

anileapen avatar Feb 14 '21 18:02 anileapen

Automation id seems to be dynamic and name also does not work. Following is what i got

"/Pane[@Name="Desktop 1"][@ClassName="#32769"]/Window[@Name="Travel Network"][@ClassName="SWT_Window0"]/Pane[@ClassName="SWT_Window0"]/Pane[@ClassName="SWT_Window0"]/Pane[@ClassName="SWT_Window0"]/Pane[@ClassName="SWT_Window0"]/Edit[@Name="Password"][@ClassName="Edit"]"

smtripathi99 avatar Feb 14 '21 19:02 smtripathi99