1

there is a button in the page with the sintax below

<div _ngcontent-cnw-c181="" class="col text-center ng-star-inserted">
<p _ngcontent-cnw-c181="" class="text-primary font-weight-bold">
Click the button below 
</p>
<button _ngcontent-cnw-c181="" type="button" routerlink="/web/click" class="btn btn-primary" tabindex="0" ng-reflect-router-link="/web/click">
<i _ngcontent-cnw-c181="" aria-hidden="true" class="fa fa-check-circle"></i>
Click Here
</button>
</div>

but when I try to localize it using Locator, it returns the error: Microsoft.Playwright.PlaywrightException: 'Unknown engine "routerlink" while parsing selector routerlink=/web/click'

Page.Locator("routerlink=/web/click").ClickAsync();

The only solution I found is by searching for "text=Click here" but I would like to use the "routerlink" keyword instead because the text might change more often in the future.

Onixy
  • 35
  • 1
  • 5

1 Answers1

1

This should work: Page.Locator("//button[@routerlink='/web/click']").ClickAsync();

Christian Baumann
  • 3,188
  • 3
  • 20
  • 37
  • Sadly not. The sintax is of course right but it went to timeout. I added some code in the description, it might help – Onixy Apr 07 '22 at 13:14
  • What's the exact error message? – Christian Baumann Apr 07 '22 at 14:12
  • Message: System.TimeoutException : Timeout 30000ms exceeded. =========================== logs =========================== waiting for selector "//child[@routerlink='/web/click']" ============================================================ Stack Trace: Connection.InnerSendMessageToServerAsync[T](String guid, String method, Object args) line 161 – Onixy Apr 07 '22 at 16:38
  • Ouch, the locator should be `//button[@routerlink='/web/click']`, I've updated the answer. Please try again. – Christian Baumann Apr 08 '22 at 06:46
  • 1
    Now it's working, thank you very much. By the chance do you have any doc reference about this sintax? I've never seen before. I'm refering to the "//" and "[@rounterlink" – Onixy Apr 08 '22 at 07:10
  • 1
    There's tons of. It's an `xpath` and it gets the element by the `attribute value`. Those to terms bring up plenty results in Google. – Christian Baumann Apr 08 '22 at 07:28