question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

XPath equivalent of FindElementByName doesn't work

See original GitHub issue

Consider the following code. Why doesn’t the XPath work as expected?

// works
var header = App.Session.FindElementByName("NIEUW FORMULIER");

// throws an exception
header = App.Session.FindElementByXPath("//*[@Name='NIEUW FORMULIER']");

The XML source up to the element in question:

<?xml version=\"1.0\" encoding=\"utf-16\"?>
<Window AcceleratorKey=\"\" AccessKey=\"\" AutomationId=\"TitleBar\" ClassName=\"ApplicationFrameWindow\" FrameworkId=\"Win32\" HasKeyboardFocus=\"False\" HelpText=\"\" IsContentElement=\"False\" IsControlElement=\"True\" IsEnabled=\"True\" IsKeyboardFocusable=\"False\" IsOffscreen=\"False\" IsPassword=\"False\" IsRequiredForForm=\"False\" ItemStatus=\"\" ItemType=\"\" LocalizedControlType=\"\" Name=\"Accent Mobile Forms\" Orientation=\"None\" ProcessId=\"7932\" RuntimeId=\"42.2688684\" x=\"-8\" y=\"0\" width=\"1483\" height=\"838\" CanMaximize=\"False\" CanMinimize=\"False\" IsModal=\"False\" WindowVisualState=\"Normal\" WindowInteractionState=\"Running\" IsTopmost=\"False\" CanRotate=\"False\" CanResize=\"False\" CanMove=\"False\" IsAvailable=\"True\">
    <Window AcceleratorKey=\"\" AccessKey=\"\" AutomationId=\"\" ClassName=\"Windows.UI.Core.CoreWindow\" FrameworkId=\"XAML\" HasKeyboardFocus=\"False\" HelpText=\"\" IsContentElement=\"True\" IsControlElement=\"True\" IsEnabled=\"True\" IsKeyboardFocusable=\"False\" IsOffscreen=\"False\" IsPassword=\"False\" IsRequiredForForm=\"False\" ItemStatus=\"\" ItemType=\"\" LocalizedControlType=\"venster\" Name=\"Accent Mobile Forms\" Orientation=\"None\" ProcessId=\"9440\" RuntimeId=\"42.4852662\" x=\"1\" y=\"40\" width=\"1465\" height=\"789\">
        <Window AcceleratorKey=\"\" AccessKey=\"\" AutomationId=\"\" ClassName=\"Popup\" FrameworkId=\"XAML\" HasKeyboardFocus=\"False\" HelpText=\"\" IsContentElement=\"True\" IsControlElement=\"True\" IsEnabled=\"True\" IsKeyboardFocusable=\"False\" IsOffscreen=\"False\" IsPassword=\"False\" IsRequiredForForm=\"False\" ItemStatus=\"\" ItemType=\"\" LocalizedControlType=\"venster\" Name=\"Pop-up\" Orientation=\"None\" ProcessId=\"9440\" RuntimeId=\"42.4852662.2.1\" x=\"1\" y=\"773\" width=\"1465\" height=\"56\">
            <AppBar AcceleratorKey=\"\" AccessKey=\"\" AutomationId=\"\" ClassName=\"ApplicationBar\" FrameworkId=\"XAML\" HasKeyboardFocus=\"False\" HelpText=\"\" IsContentElement=\"True\" IsControlElement=\"True\" IsEnabled=\"True\" IsKeyboardFocusable=\"False\" IsOffscreen=\"False\" IsPassword=\"False\" IsRequiredForForm=\"False\" ItemStatus=\"\" ItemType=\"\" LocalizedControlType=\"app-balk\" Name=\"\" Orientation=\"None\" ProcessId=\"9440\" RuntimeId=\"42.4852662.2.67\" x=\"1\" y=\"773\" width=\"1465\" height=\"55\" ExpandCollapseState=\"Collapsed\" ToggleState=\"Off\" IsAvailable=\"True\">
                <Text AcceleratorKey=\"\" AccessKey=\"\" AutomationId=\"AppName\" ClassName=\"TextBlock\" FrameworkId=\"XAML\" HasKeyboardFocus=\"False\" HelpText=\"\" IsContentElement=\"True\" IsControlElement=\"True\" IsEnabled=\"True\" IsKeyboardFocusable=\"False\" IsOffscreen=\"False\" IsPassword=\"False\" IsRequiredForForm=\"False\" ItemStatus=\"\" ItemType=\"\" LocalizedControlType=\"tekst\" Name=\"ACCENT MOBILE FORMS\" Orientation=\"None\" ProcessId=\"9440\" RuntimeId=\"42.4852662.2.68\" x=\"636\" y=\"779\" width=\"196\" height=\"24\" />
                <Text AcceleratorKey=\"\" AccessKey=\"\" AutomationId=\"AppVersion\" ClassName=\"TextBlock\" FrameworkId=\"XAML\" HasKeyboardFocus=\"False\" HelpText=\"\" IsContentElement=\"True\" IsControlElement=\"True\" IsEnabled=\"True\" IsKeyboardFocusable=\"False\" IsOffscreen=\"False\" IsPassword=\"False\" IsRequiredForForm=\"False\" ItemStatus=\"\" ItemType=\"\" LocalizedControlType=\"tekst\" Name=\"ACCEPT - Versie 2017.6.29.4\" Orientation=\"None\" ProcessId=\"9440\" RuntimeId=\"42.4852662.2.69\" x=\"639\" y=\"803\" width=\"184\" height=\"20\" />
                <Text AcceleratorKey=\"\" AccessKey=\"\" AutomationId=\"\" ClassName=\"TextBlock\" FrameworkId=\"XAML\" HasKeyboardFocus=\"False\" HelpText=\"\" IsContentElement=\"True\" IsControlElement=\"True\" IsEnabled=\"True\" IsKeyboardFocusable=\"False\" IsOffscreen=\"True\" IsPassword=\"False\" IsRequiredForForm=\"False\" ItemStatus=\"\" ItemType=\"\" LocalizedControlType=\"tekst\" Name=\"\" Orientation=\"None\" ProcessId=\"9440\" RuntimeId=\"42.4852662.2.70\" x=\"-299\" y=\"-124\" width=\"0\" height=\"0\">
                    <HyperLink AcceleratorKey=\"\" AccessKey=\"\" AutomationId=\"\" ClassName=\"Hyperlink\" FrameworkId=\"XAML\" HasKeyboardFocus=\"False\" HelpText=\"\" IsContentElement=\"True\" IsControlElement=\"True\" IsEnabled=\"True\" IsKeyboardFocusable=\"True\" IsOffscreen=\"False\" IsPassword=\"False\" IsRequiredForForm=\"False\" ItemStatus=\"\" ItemType=\"\" LocalizedControlType=\"hyperlink\" Name=\"ms-windows-store://navigatetopage/?Id=LOB\" Orientation=\"None\" ProcessId=\"9440\" RuntimeId=\"42.4852662.2.71\" x=\"-299\" y=\"-124\" width=\"0\" height=\"0\" />
                </Text>
            </AppBar>
        </Window>
        <Text AcceleratorKey=\"\" AccessKey=\"\" AutomationId=\"\" ClassName=\"TextBlock\" FrameworkId=\"XAML\" HasKeyboardFocus=\"False\" HelpText=\"\" IsContentElement=\"True\" IsControlElement=\"True\" IsEnabled=\"True\" IsKeyboardFocusable=\"False\" IsOffscreen=\"False\" IsPassword=\"False\" IsRequiredForForm=\"False\" ItemStatus=\"\" ItemType=\"\" LocalizedControlType=\"tekst\" Name=\"R028 - ACCENT INDUSTRY &amp; PRODUCTION ROESELARE\" Orientation=\"None\" ProcessId=\"9440\" RuntimeId=\"42.4852662.2.50\" x=\"14\" y=\"59\" width=\"625\" height=\"25\" />
        <Text AcceleratorKey=\"\" AccessKey=\"\" AutomationId=\"\" ClassName=\"TextBlock\" FrameworkId=\"XAML\" HasKeyboardFocus=\"False\" HelpText=\"\" IsContentElement=\"True\" IsControlElement=\"True\" IsEnabled=\"True\" IsKeyboardFocusable=\"False\" IsOffscreen=\"False\" IsPassword=\"False\" IsRequiredForForm=\"False\" ItemStatus=\"\" ItemType=\"\" LocalizedControlType=\"tekst\" Name=\"ACTUM\" Orientation=\"None\" ProcessId=\"9440\" RuntimeId=\"42.4852662.2.51\" x=\"694\" y=\"45\" width=\"78\" height=\"30\" />
        <Text AcceleratorKey=\"\" AccessKey=\"\" AutomationId=\"\" ClassName=\"TextBlock\" FrameworkId=\"XAML\" HasKeyboardFocus=\"False\" HelpText=\"\" IsContentElement=\"True\" IsControlElement=\"True\" IsEnabled=\"True\" IsKeyboardFocusable=\"False\" IsOffscreen=\"False\" IsPassword=\"False\" IsRequiredForForm=\"False\" ItemStatus=\"\" ItemType=\"\" LocalizedControlType=\"tekst\" Name=\"Klantnr: 56703 - POPERINGE\" Orientation=\"None\" ProcessId=\"9440\" RuntimeId=\"42.4852662.2.52\" x=\"639\" y=\"75\" width=\"188\" height=\"20\" />
        <Text AcceleratorKey=\"\" AccessKey=\"\" AutomationId=\"\" ClassName=\"TextBlock\" FrameworkId=\"XAML\" HasKeyboardFocus=\"False\" HelpText=\"\" IsContentElement=\"True\" IsControlElement=\"True\" IsEnabled=\"True\" IsKeyboardFocusable=\"False\" IsOffscreen=\"False\" IsPassword=\"False\" IsRequiredForForm=\"False\" ItemStatus=\"\" ItemType=\"\" LocalizedControlType=\"tekst\" Name=\"ULA NAERT\" Orientation=\"None\" ProcessId=\"9440\" RuntimeId=\"42.4852662.2.53\" x=\"1357\" y=\"59\" width=\"96\" height=\"25\" />
        <Text AcceleratorKey=\"\" AccessKey=\"\" AutomationId=\"\" ClassName=\"TextBlock\" FrameworkId=\"XAML\" HasKeyboardFocus=\"False\" HelpText=\"\" IsContentElement=\"True\" IsControlElement=\"True\" IsEnabled=\"True\" IsKeyboardFocusable=\"False\" IsOffscreen=\"False\" IsPassword=\"False\" IsRequiredForForm=\"False\" ItemStatus=\"\" ItemType=\"\" LocalizedControlType=\"tekst\" Name=\"Favorite\" Orientation=\"None\" ProcessId=\"9440\" RuntimeId=\"42.4852662.2.54\" x=\"912\" y=\"116\" width=\"30\" height=\"30\" />
        <Group AcceleratorKey=\"\" AccessKey=\"\" AutomationId=\"asbContact\" ClassName=\"AutoSuggestBox\" FrameworkId=\"XAML\" HasKeyboardFocus=\"False\" HelpText=\"\" IsContentElement=\"True\" IsControlElement=\"True\" IsEnabled=\"True\" IsKeyboardFocusable=\"False\" IsOffscreen=\"False\" IsPassword=\"False\" IsRequiredForForm=\"False\" ItemStatus=\"\" ItemType=\"\" LocalizedControlType=\"groep\" Name=\"\" Orientation=\"None\" ProcessId=\"9440\" RuntimeId=\"42.4852662.2.55\" x=\"950\" y=\"111\" width=\"440\" height=\"41\">
            <Edit AcceleratorKey=\"\" AccessKey=\"\" AutomationId=\"TextBox\" ClassName=\"TextBox\" FrameworkId=\"XAML\" HasKeyboardFocus=\"False\" HelpText=\"\" IsContentElement=\"True\" IsControlElement=\"True\" IsEnabled=\"True\" IsKeyboardFocusable=\"True\" IsOffscreen=\"False\" IsPassword=\"False\" IsRequiredForForm=\"False\" ItemStatus=\"\" ItemType=\"\" LocalizedControlType=\"bewerken\" Name=\"Zoek contact\" Orientation=\"None\" ProcessId=\"9440\" RuntimeId=\"42.4852662.2.72\" x=\"950\" y=\"111\" width=\"440\" height=\"41\">
                <Text AcceleratorKey=\"\" AccessKey=\"\" AutomationId=\"\" ClassName=\"TextBlock\" FrameworkId=\"XAML\" HasKeyboardFocus=\"False\" HelpText=\"\" IsContentElement=\"True\" IsControlElement=\"True\" IsEnabled=\"True\" IsKeyboardFocusable=\"False\" IsOffscreen=\"False\" IsPassword=\"False\" IsRequiredForForm=\"False\" ItemStatus=\"\" ItemType=\"\" LocalizedControlType=\"tekst\" Name=\"Zoek contact\" Orientation=\"None\" ProcessId=\"9440\" RuntimeId=\"42.4852662.2.75\" x=\"966\" y=\"118\" width=\"108\" height=\"25\" />
                <Button AcceleratorKey=\"\" AccessKey=\"\" AutomationId=\"QueryButton\" ClassName=\"Button\" FrameworkId=\"XAML\" HasKeyboardFocus=\"False\" HelpText=\"\" IsContentElement=\"True\" IsControlElement=\"True\" IsEnabled=\"True\" IsKeyboardFocusable=\"False\" IsOffscreen=\"False\" IsPassword=\"False\" IsRequiredForForm=\"False\" ItemStatus=\"\" ItemType=\"\" LocalizedControlType=\"knop\" Name=\"\" Orientation=\"None\" ProcessId=\"9440\" RuntimeId=\"42.4852662.2.76\" x=\"1347\" y=\"111\" width=\"43\" height=\"41\" />
            </Edit>
        </Group>
        <Button AcceleratorKey=\"\" AccessKey=\"\" AutomationId=\"addContactButton\" ClassName=\"Button\" FrameworkId=\"XAML\" HasKeyboardFocus=\"False\" HelpText=\"\" IsContentElement=\"True\" IsControlElement=\"True\" IsEnabled=\"True\" IsKeyboardFocusable=\"True\" IsOffscreen=\"False\" IsPassword=\"False\" IsRequiredForForm=\"False\" ItemStatus=\"\" ItemType=\"\" LocalizedControlType=\"knop\" Name=\"\" Orientation=\"None\" ProcessId=\"9440\" RuntimeId=\"42.4852662.2.56\" x=\"1395\" y=\"111\" width=\"63\" height=\"41\" />
        <Text AcceleratorKey=\"\" AccessKey=\"\" AutomationId=\"\" ClassName=\"TextBlock\" FrameworkId=\"XAML\" HasKeyboardFocus=\"False\" HelpText=\"\" IsContentElement=\"True\" IsControlElement=\"True\" IsEnabled=\"True\" IsKeyboardFocusable=\"False\" IsOffscreen=\"False\" IsPassword=\"False\" IsRequiredForForm=\"False\" ItemStatus=\"\" ItemType=\"\" LocalizedControlType=\"tekst\" Name=\"NIEUW FORMULIER\" Orientation=\"None\" ProcessId=\"9440\" RuntimeId=\"42.4852662.2.57\" x=\"29\" y=\"165\" width=\"157\" height=\"24\" />

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Exoowcommented, Jul 20, 2017

@yodurr So you don’t consider it a bug that XPath selectors don’t work when used on Driver.FindElement() but only in context of another element? Sorry but I have to disagree.

0reactions
yodurrcommented, Jul 17, 2017

please open a new issue on xpath performance. any specific scenario with current speed and target speed would be helpful. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Selenium WebDriver findElement(By.xpath()) not working ...
I've tried many things, such as: element = findElement(By.xpath("//[@test-id='test-username']"));. The error ...
Read more >
How to find element by XPath in Selenium with Example
Use the id and these attributes to construct XPath, which, in turn, will locate the first name field. Let's write XPath in the...
Read more >
How to handle the driver.findElementByName() deprecattion
One workaround for deprecated/removed Text Locator strategy is : String text1 = "//android.widget.TextView[@text='Test']" driver.findElement(By.
Read more >
Unable to click on Xpath element even the correct path
The below code is solved my problem..:) String pageCount = driver.findElement(By.xpath("//span[@id='paginationPageCount']")).
Read more >
A practical Guide for Finding Elements with Selenium
A practical Guide for Finding Elements with Selenium · 1) Find Element By ID · 2) Find Element By Name · 3) Find...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found