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.