Topic for comments about Browser library keyword Get Element By Role
Hi Rene,
when I try to select a locator on a website I get the followin error message:
Error: locator.waitFor: Error: strict mode violation: getByRole(âlinkâ, { name: âComputersâ }) resolved to 2 elements:
1) Computersâ” aka getByRole(âlinkâ, { name: âComputersâ }).first()
2) Computersâ” aka getByRole(âlinkâ, { name: âComputersâ }).nth(1)
With the keyword âGet Element by Roleâ I couldnât find an option to select one them like I can in PlayWright itself. Is there another way to do it?
There are two elements with the same attributes.
You can get all these elements by adding all_elements
to True
with the keyword Get Element By Role
or disable the strict mode before.
then just add " >> nth=0
" to the returned selector to get only the first one.
Hi Rene,
when I use the keyword like you mentioned it I will get a list of locators. Would it make sense to add that string to the returned selector? Maybe I just missunderstood you.
I found out that the following also works:
Click on
[Arguments] ${item}
${element} = Get Element By Role link all_elements=True name=${item}
Click ${element}[1]
Oh right.
You just take the first element of the list.
Hi Rene,
How exactly to use regular expr in âget element by roleâ ?
I donât think giving an regular expe is working.
eg:
${login_button} get element by role button name=Login\s*In
Hi @RatexMak,
See the regex example in the help for Get Element By Role
${button} Get Element By Role button name=/submit/i
In your case you would need to do something like:
${login_button} get element by role button name=/Login\s*In/
You might also want to consider which flags if any you need, in the example from the help they used the case insensitive flag (i)
Dave.
Thank you, Damies13!
I have re-read the doument, and notices the regex should be following JavaScript model. I have try several regex after that.
And now âname=/Login\s*In/gmâ is working for me.
Thank you again for your generous help!
So sorry to bother again.
I was trying to use âget element by roleâ keyword in RF and have âset selector prefixâ previously. However, it seems that i cannot id the button with name=âQueryâ in a iframe.
Is âset selector prefixâ working for âget element by roleâ? Or any other suggestions?
And I believe the prefix is working for âclickâ, how do i get the locator of the query_button, and pass it to the âclickâ function?
set selector prefix xpath=//iframe[@name=\"pdiv_page-mainIframe\"] >>>
${query_button} get element by role button name=Query
click ${query_button}
page.frame_locator(âiframe[name="whCreate"]â).get_by_role(ârowâ, name=âææäžâ).locator(âinput[name="s\:scProjCode"]â).click()
Hello everyone,
Iâm trying to get a child element by role using the cascade syntax and itâs not working, as described here:
Could you please help me on this?
Iâm new to this forum as well, so I apologize for posting the same question in two different places, but I really need this.
Thanks a lot.