0

I'm doing something like this:

await PAGE1.get_by_role("button", name="mono").nth(3).click()
await PAGE2.get_by_role("button", name="mono").nth(3).click()

I've been trying to figure out if there was a way to set up a locator, so I can just write:

mylocator = .......
await PAGE1.mylocator.click()
await PAGE2.mylocator.click()

But I can't figure out if it's even posible in python... ??

arjepsen
  • 11
  • 1

1 Answers1

0

Try doing this:

# Define the locator
mylocator = page.locator("button[name='mono']")

# Use the locator on PAGE1
await PAGE1.wait_for_selector(mylocator)
await mylocator.nth(3).click()

# Use the locator on PAGE2
await PAGE2.wait_for_selector(mylocator)
await mylocator.nth(3).click()
NYC Coder
  • 7,424
  • 2
  • 11
  • 24