简体   繁体   English

如何在 c# 中获取已初始化的 IWebElement 的 XPATH

[英]How to fetch the XPATH of an initialized IWebElement in c#

I am using WinappDriver/Appium to automate an windows application project.我正在使用 WinappDriver/Appium 来自动化 Windows 应用程序项目。

I have initialized an Parent WindowsElement using Xpath.我已经使用 Xpath 初始化了一个父 WindowsElement。

Now once the Element is initialized i want to get the XPATH of the (Parent) Element which was used so that i can get the Child elements using the Parent XPATH.现在,一旦元素被初始化,我想获取所使用的(父)元素的 XPATH,以便我可以使用父 XPATH 获取子元素。

session = UiaWindowDriver.CreateSession(new Uri(WindowsApplicationDriverUrl), uiaDriverOptions); //WindowsDriver<WindowsElement>
var Window = session.GetWindow("//Window[@Name=\"Sample Application\"]"); //Returns me an WindowsElement

Now as i got the Window (ie Parent Control) i want to get the child elements of the Parent Control.现在,当我获得窗口(即父控件)时,我想获取父控件的子元素。

Any help is appreciated.任何帮助表示赞赏。

Many Thanks !!!非常感谢 !!!

Why create it as a Window?为什么将其创建为窗口? You can just create that as a WindowsElement like...您可以将其创建为 WindowsElement 之类的...

WindowsElement parentWindow = session.FindElementByXPath("//Window[@Name=\"Sample Application\"]");

THEN this will allow you to look for additional elements isolated to this window like so..然后,这将允许您查找与此窗口隔离的其他元素,如下所示..

WindowsElement someElement = parentWindow.FindElementByXPath("...");

In some cases it may throw an error related to casting, you can resolve that like so...在某些情况下,它可能会引发与转换相关的错误,您可以像这样解决...

WindowsElement someElement = (WindowsElement)parentWindow.FindElementByXPath("...");

I am almost certain this will work in your case.我几乎可以肯定这将适用于您的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM