javascript - Playwright Error when clicking Anchor Element - Stack Overflow

I have following anchor Element on the page for which I am writing Playwright Tests<a _ngcontent-ng-

I have following anchor Element on the page for which I am writing Playwright Tests

 <a _ngcontent-ng-c643490139="" mat-menu-item="" tabindex="0" class="mat-mdc-menu-item mat-mdc-focus-indicator ng-tns-c2786309385-2 ng-star-inserted" href="/event-partner" role="menuitem" aria-disabled="false" style="">
<span class="mat-mdc-menu-item-text"><span _ngcontent-ng-c643490139="">Eventpartner</span></span><div matripple="" class="mat-ripple mat-mdc-menu-ripple"></div>
<!---->
</a>

Its an anchor Tag with a role of menuitem. Accessing it via following locator should work:

//Open the Menu whose name is Daten
await page.locator('a').filter({ hasText: 'Daten' }).click();

await page.getByRole('menuitem', { name: 'Eventpartner' }).click();

But I get the following error in my Test:

Error: locator.click: Test timeout of 30000ms exceeded.

Call log:

  • waiting for getByRole('menuitem', { name: 'Eventpartner' })
    • locator resolved to …
  • attempting click action 2 × waiting for element to be visible, enabled and stable
    • element is visible, enabled and stable
    • scrolling into view if needed
    • done scrolling
    • … from … subtree intercepts pointer events
    • retrying click action
    • waiting 20ms
    • waiting for element to be visible, enabled and stable
  • element was detached from the DOM, retrying

How can I fix this issue?

The website here removes the Element referred to by locator resolved to in the above error message.

<a tabindex="0" role="menuitem" mat-menu-item="" href="/event-partner" aria-disabled="false" _ngcontent-ng-c2888663785="" class="mat-mdc-menu-item mat-mdc-focus-indicator ng-tns-c2786309385-2 ng-star-inserted">…</a>

Following does work, but I dont know whats the difference is with clicking the Element:

 await page.locator('a').filter({ hasText: 'Daten' }).click();


await page.getByRole('menuitem', { name: 'Eventpartner' }).press('Enter');

I have following anchor Element on the page for which I am writing Playwright Tests

 <a _ngcontent-ng-c643490139="" mat-menu-item="" tabindex="0" class="mat-mdc-menu-item mat-mdc-focus-indicator ng-tns-c2786309385-2 ng-star-inserted" href="/event-partner" role="menuitem" aria-disabled="false" style="">
<span class="mat-mdc-menu-item-text"><span _ngcontent-ng-c643490139="">Eventpartner</span></span><div matripple="" class="mat-ripple mat-mdc-menu-ripple"></div>
<!---->
</a>

Its an anchor Tag with a role of menuitem. Accessing it via following locator should work:

//Open the Menu whose name is Daten
await page.locator('a').filter({ hasText: 'Daten' }).click();

await page.getByRole('menuitem', { name: 'Eventpartner' }).click();

But I get the following error in my Test:

Error: locator.click: Test timeout of 30000ms exceeded.

Call log:

  • waiting for getByRole('menuitem', { name: 'Eventpartner' })
    • locator resolved to …
  • attempting click action 2 × waiting for element to be visible, enabled and stable
    • element is visible, enabled and stable
    • scrolling into view if needed
    • done scrolling
    • … from … subtree intercepts pointer events
    • retrying click action
    • waiting 20ms
    • waiting for element to be visible, enabled and stable
  • element was detached from the DOM, retrying

How can I fix this issue?

The website here removes the Element referred to by locator resolved to in the above error message.

<a tabindex="0" role="menuitem" mat-menu-item="" href="/event-partner" aria-disabled="false" _ngcontent-ng-c2888663785="" class="mat-mdc-menu-item mat-mdc-focus-indicator ng-tns-c2786309385-2 ng-star-inserted">…</a>

Following does work, but I dont know whats the difference is with clicking the Element:

 await page.locator('a').filter({ hasText: 'Daten' }).click();


await page.getByRole('menuitem', { name: 'Eventpartner' }).press('Enter');
Share Improve this question edited Mar 25 at 10:21 user1107888 asked Mar 25 at 9:35 user1107888user1107888 1,5255 gold badges35 silver badges58 bronze badges 1
  • I don't think the few lines of markup here is enough to reproduce the problem. Likely this is a dynamic, complex site that needs to be included as part of the question. – ggorlen Commented Mar 27 at 5:44
Add a comment  | 

1 Answer 1

Reset to default 0

Issue is that the menu item vanishes on click because the menu isn’t fully opened.
To fix this, open the menu, then click the link.
For example:

// 1. Click the button that opens the menu
await page.getByRole('button', { name: 'Menu' }).click();

// 2. Now click the menu item
await page.getByRole('menuitem', { name: 'Eventpartner' }).click();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744206379a4563124.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信