Element click not working

Hi. I’m new to Appium so apologies if this seems like a very basic user error :slight_smile:

I’m using Appium to test an app via Browserstack, and need to click on an element.

So my code at the moment is;

const okButton =  driver.elementById('android:id/button1');
okButton.click(); 

However, when I run this, I get the following error;

TypeError: okButton.click is not a function

Any ideas on what I’m doing wrong?

thanks.

Can you run locally? Nobody here can test Browserstack without paying for it.

Thanks for the reply @wreed. I’ve now got this working. I’d forgot the async command.

1 Like

I’m glad you’ve gotten it working. I’m curious if the async command is a Browserstack thing? I’m not familiar with it.

Sorry, I should have expanded my answer.

This is my working code;

driver.init(desiredCaps)
.then (async function () {
let element = await driver.element("xpath", 
".//android.widget.Button[@text='OK']");
await element.click();
})
.fin(function() {
return driver.quit();
})
.done();

Ah, I think that’s Javascript. Thanks!