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.

FindElementByAccessibilityId throws WebDriverException

See original GitHub issue

Hi Team,

I am using WinAppDriver to automate my windows application. On using FindElementByAccessibilityId to find the element on the application, I am getting the exception “OpenQA.Selenium.WebDriverException: 'An element could not be located on the page using the given search parameters.'”

I am using Inspect tool to inspect the element on the application and getting the value of the property ‘AutomationId’ and providing as string for FindElementByAccessibilityId method.

Could someone help me to understand why I am getting the exception?

Thanks in advance

My Sample Code:

public void TestMethod1()
        {
            //WinAppDriver and Application started before the test execution
            String _appName = "GUIApplication";
            AppiumOptions dc= new AppiumOptions();
            AppiumOptions mc= new AppiumOptions();
            dc.AddAdditionalCapability("platformName", "Windows");
            dc.AddAdditionalCapability("app", "Root");
            WindowsDriver<WindowsElement> session1= new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), dc);
            session1.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(100);
            AppiumWebElement element = session1.FindElementByName(_appName);
            string AppHandle= element.GetAttribute("NativeWindowHandle");
            int HandleInt= int.Parse(AppHandle);
            string HandleHex = HandleInt.ToString("x");
            mc.AddAdditionalCapability("appTopLevelWindow", HandleHex);
             WindowsDriver<WindowsElement> current = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), mc);
            current.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(100);
            bool result = current.FindElementByAccessibilityId("ABCDEF").Displayed; //Throws Exception
        }

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
Shakevgcommented, Sep 7, 2021

@iamkrk Real extracted by WinAppDriver page source can be different from Inspector Could you save the page source and check that control really presents in XML with the expected attributes (use driver.PageSource) and then check that XPath working using http://xpather.com/? Xpath will be something like: //*[@AutomationId=‘FirsatNameTextbox_First Name *’]

0reactions
iamkrkcommented, Sep 7, 2021

Nope. Still throws the exception.

If I just use as below it works.

bool result = current.FindElementByName("First Name *").Displayed;

Am curious to understand why on using FindElementByAccessibilityId throws exception.

Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can not catch WebDriverException for certain elements
I have the following elements identified in a page object.. public WindowsElement usernameField => _session.FindElementByAccessibilityId(" ...
Read more >
"OpenQA.Selenium.WebDriverException" exception thrown ...
WebDriverException " exception thrown sometimes when trying to locate elements by ... FindElementByAccessibilityId(String selector)
Read more >
io.appium.java_client.FindsByAccessibilityId java code ...
{@inheritDoc} * * @throws WebDriverException when current session doesn't support the given selector or when * value of the selector is not consistent....
Read more >
Casting exception in io.appium.java
I am having an issue while running the following code,it's throwing ... WebDriverException: Returned value cannot be converted to WebElement: ...
Read more >
AndroidDriver<T extends org.openqa.selenium.WebElement>
Throws : org.openqa.selenium.WebDriverException - his method doesn't work against native app UI. findElementByPartialLinkText.
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