Rayrun

How do I automate selecting options from a dropdown menu in a Salesforce application using Playwright?

Answer

Selecting Options from a Dropdown in Salesforce

To automate selecting options from a dropdown menu in a Salesforce application using @playwright/test, you can use the selectOption method. This method waits for actionability checks and selects the specified options.

Here's an example using TypeScript:

import { test } from '@playwright/test';

test('Select option from dropdown', async ({ page }) => {
  await page.goto('https://ray.run/salesforce-app');

  // Locate the dropdown element
  const dropdown = await page.locator('#dropdown-id');

  // Select option by value
  await dropdown.selectOption('blue');

  // Select option by label
  await dropdown.selectOption({ label: 'Label text' });

  // Select multiple options (if applicable)
  await dropdown.selectOption(['blue', { label: 'Label text' }]);
});

If you need to bypass actionability checks, you can use the force option:

await dropdown.selectOption('blue', { force: true });

Keep in mind that actions like page.click() support the force option, which disables non-essential actionability checks. Passing a truthy force to page.click() will not check whether the target element actually receives click events.

In addition to selecting options from dropdowns, Playwright provides other useful methods for interacting with elements, such as mouse clicks, hovering, and scrolling elements into view.

Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

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 luc@ray.run.