XPath Samples

The following table lists sample XPath queries and explains the semantics for each query.
XPath String Description
desktop.Find("/Shell[@caption='SWT Test Application'] ") Finds the first top-level Shell with the given caption.
desktop.Find("//MenuItem[@caption='Control']") Finds the MenuItem in any hierarchy with the given caption.
myShell.Find("//MenuItem[@caption!='Control']") Finds an MenuItem in any child hierarchy of myShell that does not have the given caption.
myShell.Find("Menu[@caption='Control']/MenuItem[@caption!='Control']") Looks for a specified MenuItem with the specified Menu as parent that has myShell as parent.
myShell.Find("//MenuItem[@caption='Control' and @windowid='20']") Finds a MenuItem in any child hierarchy of myWindow with the given caption and windowId.
myShell.Find("//MenuItem[@caption='Control' or @windowid='20']") Finds a MenuItem in any child hierarchy of myWindow with the given caption or windowId.
desktop.FindAll("/Shell[2]/*/PushButton") Finds all PushButtons that have an arbitrary parent that has the second top-level shell as parent.
desktop.FindAll("/Shell[2]//PushButton") Finds all PushButtons that use the second shell as direct or indirect parent.
myBrowser.Find("//FlexApplication[1]//FlexButton[@caption='ok']") Looks up the first FlexButton within the first FlexApplication within the given browser.
myBrowser.FindAll("//td[@class='abc*']//a[@class='xyz']") Finds all link elements with attribute class xyz that are direct or indirect children of td elements with attribute class abc*.