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

XPath query does not return root. #629

Open
grokys opened this issue May 7, 2024 · 0 comments
Open

XPath query does not return root. #629

grokys opened this issue May 7, 2024 · 0 comments

Comments

@grokys
Copy link

grokys commented May 7, 2024

Describe the bug

XPath queries such as AutomationElement.FindFirstByXPath do not consider the root element for queries so queries such as //Window return no elements.

Code snippets

[Test]
public void WindowFindFirst()
{
    RestartApplication();

    var window = Application.GetMainWindow(Automation);
    var result = window.FindFirstByXPath($"//Window");
    Assert.That(result, Is.Not.Null);
}

Additional context

An XPath query should consider the root of the query in the results. For example, go to http://xpather.com/ and enter //app: the root element is returned. This behavior is correct in e.g. WinAppDriver.

Alternatively, run the following code:

var doc = XDocument.Parse("<root><child>text</child></root>");
var node = doc.Root!.XPathSelectElement("//root"); // root is found
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

1 participant