Reputation: 803
I am running protractor on an ionic (4) angular (7) app that is able to run tests using appium.
The test I have work fine when it tries to locate elements by CSS but fails when locating by ID.
I get
NoSuchElementError: No element found using locator: By(css selector, *[id="login-button"])
However the test runs fine on browser without cordova/android but I noticed all IDs are missing in the HTML of the cordova/android app
which are fine in the browser (non app) note: id="login-button"
I've tried adding
var EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(button), 10000)
but then the browser waits forever.
For Example in my HTML
<ion-button id="login-button" class="login-btn" (click)="login()">LOGIN</ion-button>
Then in the test
const button = await element(by.id('login-button'))
button.click();
I expect the test to click on the button and continue to the next page but the test fails on android only.
I need to be able to search/locate by IDs because sometimes I dynamically generate IDs based on ngFor
etc. It can locate all other elements by CSS just not by ID.
Upvotes: 0
Views: 391
Reputation: 8978
First of all, read about await
keyword, how to use it, and then try
var EC = protractor.ExpectedConditions;
await browser.wait(EC.presenceOf(button), 10000)
const button = element(by.id('login-button'))
await button.click();
Then if doesn't work, ping me, we'll try something else
Upvotes: 0
Reputation: 734
It looks you can still locate them by their class
element(by.css('.login-btn.md.button.button-solid.ion-activatable.ion-focusable.hydrated'));
Or with buttonText?
element(by.buttonText("LOGIN"));
Upvotes: 0