Element.click is not a function

I cannot get my .click() to work on my button, I get the error - element.click is not a function. Can anyone help?

The element renders ok, but click() is undefined.

const wd = require("wd");
const jasmine = require("jasmine");
const chai = require("chai");
const PORT = 4723;

const config = {
    platformName: "iOS",
    platformVersion: "10",
    deviceName: "iPhone 11",
    app: "./apps/myracnative.app",
    udid: "4F94755B-6323-46B0-ACB4-469FB50BAD95",
    automationName: "XCUITest", // UiAutomator2, Espresso, or UiAutomator1 for Android

const driver = wd.promiseChainRemote("localhost", PORT);

before(async () => {
    await driver.init(config);
    await driver.sleep(10000); // wait for app to load

it("login button will be clicked", async () => {
    const element = await driver.hasElementByAccessibilityId("Log in");
    await driver.sleep(200);
    await element.click(); // element.click is not a function

My appium log shows it can find the element, but there is no mention of the click function:

[debug] [MJSONWP (30b7999b)] Calling AppiumDriver.findElements() with args: [“accessibility id”,“Log in”,“30b7999b-7759-4a19-9fea-518be038f7a3”]

[debug] [XCUITest] Executing command ‘findElements’

[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, name, class name, -ios predicate string, -ios class chain, accessibility id, css selector

[debug] [BaseDriver] Waiting up to 0 ms for condition

[debug] [WD Proxy] Matched ‘/elements’ to command name ‘findElements’

[debug] [WD Proxy] Proxying [POST /elements] to [POST] with body: {“using”:“accessibility id”,“value”:“Log in”}

[debug] [WD Proxy] Got response with status 200: {“value”:[{“ELEMENT”:“25000000-0000-0000-8E1D-000000000000”,“element-6066-11e4-a52e-4f735466cecf”:“25000000-0000-0000-8E1D-000000000000”},{“ELEMENT”:“2A000000-0000-0000-8E1D-000000000000”,“element-6066-11e4-a52e-4f735466cecf”:“2A000000-0000-0000-8E1D-000000000000”}],“sessionId”:“5C2E0576-602A-41E5-A7CE-37467D87C7B9”}

[debug] [MJSONWP (30b7999b)] Responding to client with driver.findElements() result: [{“element-6066-11e4-a52e-4f735466cecf”:“25000000-0000-0000-8E1D-000000000000”,“ELEMENT”:“25000000-0000-0000-8E1D-000000000000”},{“element-6066-11e4-a52e-4f735466cecf”:“2A000000-0000-0000-8E1D-000000000000”,“ELEMENT”:“2A000000-0000-0000-8E1D-000000000000”}]

[HTTP] <-- POST /wd/hub/session/30b7999b-7759-4a19-9fea-518be038f7a3/elements 200 198 ms - 329


This method returns an array, which you can see in the log here:

You can’t click on an array. You need to pick a single element to click.

Thanks for the reply - there is only one element with that id - do you know why its returning an array?

Sorry I don’t know your app. The reason it’s returning an Array is that this is the return type of that method. You should know that even if it returned one element in an array you’d have to extract it before you could interact with it.

Array object does not have .click() method. You can use a different method, or cycle through the 2 elements to pick the correct one and then click on it.

‘hasElementByAccessibilityId’ is boolean!

Possibly you want to use instead ‘findElementByAccessibilityId’ ?

I’m happy to be wrong here. Can you point to the code where the return type is boolean? From the log provided it is clearly calling findElements, which returns an array type:



Not sure where source code example of usage from first google link.

expect(await driver.hasElementByAccessibilityId('username input')).toBe(true)

That does seem right. Maybe log provided is incomplete.

I also can’t find javascript source for this. Still the point stands, have to click on an element, not some other programatic object.