Rayrun
โ† Back to Discord Forum

Easy way to "switch" on various outcomes on a page?

I have a page which might yield a 5 or so different outcomes. Previously in puppeteer I would do a "race" promise and then branch from that return. Is there a similar construct in Python Playwright? Seems like the only solution is to just or_ a bunch of locators together and then expect them to visible?

This thread is trying to answer question "Is there a cleaner solution in Python Playwright for handling multiple possible outcomes on a page, similar to the 'race' promise in Puppeteer?"

2 replies
last_name_input = self.page.locator("input#lastName")
zipcode_input = self.page.locator("input#zipCode")
error_text = self.page.locator("span.errorText")
patient_listing = self.page.locator("//p[text()='Patient Eligibility']")
subscriber_selection = self.page.locator("//p[text()='Subscriber Selection']")

expect(last_name_input.or_(zipcode_input).or_(error_text).or_(patient_listing).or_(subscriber_selection)).to_be_visible()

Trying to find a cleaner solution than this.

Can you describe the scenario in your code example? If I'm reading it right, you're expecting one or all of the following to be visible:

  1. An input field labeled "zipcode"
  2. An error message
  3. Some text saying "subscriber selection"

That's kinda weird to me because they're all so different. Are you using this check to ensure that the page is loaded and ready for some other actions?

Trust me that I'm asking so I can give relevant design advice, not to argue about how your app or this page behave. ๐Ÿ™‚

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].