Inspector not finding elements, specifically text fields

I’m working with the Inspector to write some tests for iOS. We’re checking out an iPhone 6, version 8.4. Every time I try to run the tests after setting them up in the inspector, I keep getting the error that element cannot be found using the parameters used. Also, while using inspector, I am able to click buttons (like a login button, or “facebook” button, but sending text to text fields never works. Could really use some guidance here.

“use strict”;

var wd = require(“wd”);
var chai = require(“chai”);
var chaiAsPromised = require(“chai-as-promised”);

chai.use(chaiAsPromised);
chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;

var desired = {
“appium-version”: “1.0”,
platformName: “iOS”,
platformVersion: “8.4”,
deviceName: “iPhone 6”,
app: “/Users/andrew/Documents/SqorMobileiOS.app”,
};

var browser = wd.promiseChainRemote(“0.0.0.0”, 4723);

browser.init(desired).then(function() {
return browser
.elementByXPath("//UIAApplication[1]/UIAWindow[1]/UIAButton[1]").click()
.sleep(10000)
.elementByXPath("//UIAApplication[1]/UIAWindow[2]/UIAScrollView[1]/UIAScrollView[1]/UIAWebView[1]/UIATextField[1]").click()
.sleep(10000)
.elementByXPath("//UIAApplication[1]/UIAWindow[2]/UIAScrollView[1]/UIAScrollView[1]/UIAWebView[1]/UIATextField[1]").sendKeys("[email protected]")
.sleep(10000)
.elementByXPath("//UIAApplication[1]/UIAWindow[2]/UIAScrollView[1]/UIAScrollView[1]/UIAWebView[1]/UIASecureTextField[1]").click()
.elementByXPath("//UIAApplication[1]/UIAWindow[2]/UIAScrollView[1]/UIAScrollView[1]/UIAWebView[1]/UIASecureTextField[1]").sendKeys(“Password”)
.elementByXPath(" //UIAApplication[1]/UIAWindow[2]/UIAScrollView[1]/UIAScrollView[1]/UIAWebView[1]/UIAButton[1]").click()
.sleep(10000)

	.fin(function() {
		return browser.quit();
	});

}).done();

We cannot interact with UIAWebView class elements directly we need to switch to webview context
Check if method getContext(); prints some context like NATIVE,WEBVIEW etc

Hi @amitjaincoer191 Thank you for the response. Can you please clarify exactly where I would need to apply that method? I am super new to this. Thanks

Something like this worked in JAVA for Android app

final Set contextNames = driver.getContextHandles();
for (final String contextName : contextNames) {
System.out.println(contextName);
if (contextName.contains(“WEBVIEW”)) {
driver.context(contextName);
}

find equivalent code in javascript and check if context as WEBVIEW is coming if yes switch to it and then try
if no then may be some other issue.

Hybrid app contains Native and WebView context

You can insert your code after this statement, once the context is switched you can easily find the elements
var browser = wd.promiseChainRemote(“0.0.0.0”, 4723);

I keep getting that undefined is not a function (regarding .contexts().

“use strict”;

var wd = require(“wd”);
var chai = require(“chai”);
var chaiAsPromised = require(“chai-as-promised”);

chai.use(chaiAsPromised);
chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;

var driver = {
“appium-version”: “1.0”,
platformName: “iOS”,
platformVersion: “8.4”,
deviceName: “iPhone 6”,
app: “/Users/andrew/Documents/SqorMobileiOS.app”,
};

var browser = wd.promiseChainRemote(“0.0.0.0”, 4723);

driver.contexts().then(function (contexts) { // get list of available views. Returns array: [“NATIVE_APP”,“WEBVIEW_1”]
return driver.context(contexts[1]); // choose the webview context
})

// do some web testing
.elementByName('Log in here  ').click()

.context('NATIVE_APP') // leave webview context

// do more native stuff here if we want

.quit() // stop webdrivage