Preface
playwrightSupport and_ and or_ positioning after v1.34
XPathand and or
xpath syntaxThe commonly used ones in this are text(), contains(), ends_with(), and starts_with()
//*[text()="text"]
//*[contains(@id, "xx")]
//*[ends-with(@name,'xx')]
//*[starts-with(@id,'xx')]
- 1
- 2
- 3
- 4
It can also support and, or, and not keyword positioning
//*[@type='submit' and @name='xx']
//*[@name='xx' or @name='yy']
//*[@type='submit' and not(contains(@name,'xxx'))]
- 1
- 2
- 3
and_ and or_positioning in playwright
and_Positioning Example
button = page.get_by_role("button").and_(page.getByTitle("Subscribe"))
- 1
or_positioning example
new_email = page.get_by_role("button", name="New")
dialog = page.get_by_text("Confirm security settings")
expect(new_email.or_(dialog)).to_be_visible()
if (dialog.is_visible()):
page.get_by_role("button", name="Dismiss").click()
new_email.click()
- 1
- 2
- 3
- 4
- 5
- 6