Using sendKeys sometimes results in InvalidElementState
map7 opened this issue · 0 comments
I'm using the following packages (tns info output) on Linux (Debian Jessie)
✔ Getting NativeScript components versions information...
✔ Component nativescript has 6.2.0 version and is up to date.
✔ Component tns-core-modules has 6.2.1 version and is up to date.
✔ Component tns-android has 6.2.0 version and is up to date.
✔ Component tns-ios has 6.2.0 version and is up to date.
I'm running on Android 7.0
The problem I'm having is when I try and sendKeys to an element on a tab or too low on the screen I get the following error;
Error: [element.sendKeys("Rasberry PI")] Error response status: 12, InvalidElementState - An element command could not be completed because the element is in an invalid state (e.g. attempting to click a disabled element). Selenium error: Cannot set the element to 'Rasberry PI'. Did you interact with the correct element?
My element on a tab looks like this;
<TabContentItem>
<StackLayout orientation="vertical">
<Label text="Make"></Label>
<TextField automationText="make" hint="Make" [(ngModel)]="_assetItem.make" class="input"></TextField>
</TabContentItem>
My test looks like this;
import { AppiumDriver, createDriver, SearchOptions, nsCapabilities } from "nativescript-dev-appium";
import { assert } from "chai";
const addContext = require('mochawesome/addContext');
describe("Asset Create", () => {
let driver: AppiumDriver;
before(async function(){
nsCapabilities.testReporter.context = this;
driver = await createDriver(); // wait for the driver instance to be created
});
after(async function () {
await driver.quit(); // destroy the driver instance
console.log("Quit driver!");
});
afterEach(async function () {
if (this.currentTest.state === "failed") {
await driver.logTestArtifacts(this.currentTest.title);
}
});
describe("After login", () => {
before(async function () {
// Enter user
const nameField = await driver.findElementByAccessibilityId("email");
await nameField.sendKeys("test@pais.com.au");
// Enter password
const passwordField = await driver.findElementByAccessibilityId("password");
await passwordField.sendKeys("testmobile");
// Login
const btnLoginTap = await driver.findElementByAccessibilityId("btnLogin");
await btnLoginTap.click();
});
afterEach(async function () {
// Nav to Home
const btnHomeNavTap = await driver.findElementByAccessibilityId("btnHome");
await btnHomeNavTap.click();
});
it.only("creates new asset", async function () {
// Nav to New Asset
const btnManualNavTap = await driver.findElementByAccessibilityId("btnNewAsset");
await btnManualNavTap.click();
// Check heading
const lblHeadingManual = await driver.findElementByAccessibilityId("headingAssetForm");
assert.equal(await lblHeadingManual.text(), "New Asset");
const tabDetails = await driver.findElementByAutomationText("tabDetails");
await tabDetails.click();
const makeField = await driver.findElementByAutomationText("make");
await makeField.sendKeys("Rasberry PI");
I expected it to type the text "Raspberry PI" into the 'make' field, but instead nothing happens and I get an error from my End to End test. The after block still runs.
I've tried the following
waiting for the field
await makeField.waitForExist(1000);
Click on it first
const makeField = await driver.findElementByAutomationText("make");
await makeField.click();
await makeField.sendKeys("Rasberry PI");
Sending through adb instead
await makeField.sendKeys("Rasberry PI", true, true);
Error
Error: [execute("mobile: shell",{"command":"input","args":["keyevent",67]})] Error response status: 13, , UnknownError - An unknown server-side error occurred while processing the command. Selenium error: An unknown server-side error occurred while processing the command. Original error: Potentially insecure feature 'adb_shell' has not been enabled. If you want to enable this feature and accept the security ramifications, please do so by following the documented instructions at https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/security.md
I can write to some TextFields if they are at the top of a screen and on the first tab. As soon as I go to the second tab I cannot type in the fields. I also cannot type in fields which are too low on the screen. I had a vertical stack of 4 fields all with labels above and I couldn't sendKeys to the last field, but if I removed some of the labels which moved the field up then I could.