dinkelberg
dinkelberg

Reputation: 9

Failed: no element found using locator: with the Id I use getUserById

This is my code in my HTML:

<h1>User list</h1>
<button class="btn btn-primary" [routerLink]="'/register'">Register</button>
<br>
    <br>
        <table class="table">
            <thead>
                <tr>
                    <th scope="col">#</th>
                    <th scope="col">name</th>
                    <th scope="col">email</th>
                </tr>
            </thead>
            <tbody>
                <tr *ngFor="let user of users$ | async">
                    <th scope="row">{{ user._id }}</th>
                    <td>
                        <a id="getUserById" routerLink="{{ user._id }}">{{ user.name }}</a>
                    </td>
                    <td>{{ user.email }}</td>
                </tr>
            </tbody>
        </table>

Protactor does not find my id "getUserById".

This is my test that I am tryint to run:

it('should go to user detail page', async () => {
    browser.waitForAngularEnabled(false);
    page.navigateTo('/users/');
    await page.getById.click();
    expect(browser.getCurrentUrl()).toContain('/users/');
});

Upvotes: 1

Views: 40

Answers (2)

Analyst
Analyst

Reputation: 911

What I guess you are trying a protractor/selenium method for getting the id of element. the best way to do that is to use element function i.e. element(by.id('goBackButton')). Now you can use this for clicking or any thing else. Lemme know if it helps

Upvotes: 0

Squiggs.
Squiggs.

Reputation: 4474

I'm not intimately familiar with Protractor, but it looks like either you haven't passed the id into the function, or the api call is wrong. If you've some sort of wrapper around Protractor then:

page.getById.click();

perhaps should be

page.getById('getUserById').click();

Otherwise see docs here:

https://www.protractortest.org/#/api?view=webdriver.By.id

await page.getById.click(); therefore should be 


var element = element(by.id('getUserById'))
element.click();

Upvotes: 1

Related Questions