Seeking to identify and target the <a>
element with an id attribute.
Attributes that may be used:
- role
- href
- title
- id
- style
- onclick
I am able to do so using role and name, but unsuccessful with id or onclick. The latter two would be beneficial for future tasks.
Clicking on the locator identified by role and name works smoothly:
point56Button = this.page.getByRole('button', {
name: 'Pole 56',
exact: true,
});
However, attempting to do it by id generates an error:
Error: locator.click: DOMException: Failed to execute 'querySelectorAll' on 'Document': '#56' is not a valid selector.
at query (<anonymous>:3329:41)
...
Snippet of website code:
<a role="button" href="#" title="Pole 56" id="56" style="width:104px;height:16px;top:611px;left:668px;text-align:Right;vertical-align:text-bottom;position:absolute;cursor:pointer;padding-top:71px;font-size:13px;color:black;" onclick="RunSubwizard('56',event);"></a>
My code snippet to locate an element by id:
point56Button = this.page.locator('#56');
Objective is to click on the element located by id
Expected outcome: open wizard
Successful in locating elements by role and name Unsuccessful in locating elements by id