Stanza
Stanza

Reputation: 565

Element could not be located using find element by Id

I am performing some UI automation and using Appium Inspector to inspect the user name text field for the Microsoft login credentials screen. When referencing an element by Id I get the error: "An element could not be located on the page using the given search parameters."

I am using Appium Inspector for Appium 2.0 and according to the recommended selector I can use either id xpath however, id gives me the error whilst using xpath works

enter image description here

The line of code which is failing:

driver.FindElementById("i0116").SendKeys("test");

Any reason why this is the case?

My environment is:

"desiredCapabilities": {
    "platformName": "Android",
    "appium:automationName": "UIAutomator2",
    "appium:deviceName": "PixelSix",
    "appium:app": "C:\\Users\\slai6\\Downloads\\MyApp.1.apk",
    "appium:platformVersion": "11",
    "appium:ensureWebviewsHavePages": true,
    "appium:nativeWebScreenshot": true,
    "appium:newCommandTimeout": 3600,
    "appium:connectHardwareKeyboard": true
  }

Upvotes: 1

Views: 443

Answers (1)

Stanza
Stanza

Reputation: 565

I realised that the Microsoft login screen was part of the 'WEBVIEW' context so I had to change the context from "NATIVE_APP".

I used:

((IContextAware)driver).Context = "WEBVIEW";

I also had to install the chrome driver using:

driverOption.AddAdditionalCapability("appium:chromedriverExecutable", chromePath);

Where the 'chromePath' is the directory where I downloaded the Chrome driver to on my local machine. I had to manually download the executable from: https://chromedriver.chromium.org/downloads

I was then able to inspect it using the Chrome inspector tool - type in chrome://inspect in address bar for google Chrome, select the emulator device form the device list and get the id from the inspector tool.

Upvotes: 0

Related Questions