<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: The Wise</title>
    <description>The latest articles on DEV Community by The Wise (@the_wise_06d8114f1ee73fe8).</description>
    <link>https://dev.to/the_wise_06d8114f1ee73fe8</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3512854%2F08442caf-5e31-4fb6-96de-fec44c5731a5.jpg</url>
      <title>DEV Community: The Wise</title>
      <link>https://dev.to/the_wise_06d8114f1ee73fe8</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/the_wise_06d8114f1ee73fe8"/>
    <language>en</language>
    <item>
      <title>Understanding page.locator().click() in Playwright</title>
      <dc:creator>The Wise</dc:creator>
      <pubDate>Wed, 08 Oct 2025 09:45:30 +0000</pubDate>
      <link>https://dev.to/the_wise_06d8114f1ee73fe8/understanding-pagelocatorclick-in-playwright-1d1m</link>
      <guid>https://dev.to/the_wise_06d8114f1ee73fe8/understanding-pagelocatorclick-in-playwright-1d1m</guid>
      <description>&lt;h2&gt;
  
  
  What is locator.click()?
&lt;/h2&gt;

&lt;p&gt;In Playwright, locator.click() is a high-level API used to simulate a mouse click on a web element. It’s part of the Locator API, which provides a robust way to interact with elements on the page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await page.getByRole('button').click();

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  This command does the following:
&lt;/h3&gt;

&lt;p&gt;Finds the element matching the selector.&lt;br&gt;
Auto-Waiting Mechanism&lt;br&gt;
Playwright automatically waits for the element to be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Attached to the DOM&lt;/li&gt;
&lt;li&gt;Visible (not hidden via CSS or layout)&lt;/li&gt;
&lt;li&gt;Enabled (not disabled)&lt;/li&gt;
&lt;li&gt;Stable (not animating or moving)
This avoids flaky tests caused by premature clicks.
Scrolls it into view if needed.&lt;/li&gt;
&lt;li&gt;If the element is outside the viewport, Playwright scrolls it into view using element.scrollIntoViewIfNeeded().
This mimics how a real user would interact with off-screen elements.
Performs a click action.&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;When you use the click() method , it does the following actions in   sequence to mimic a real user clicking experience.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; mousedown —&amp;gt; Like when the mouse is pressed, the button goes down&lt;/li&gt;
&lt;li&gt; mouseup —&amp;gt; Like when the mouse is stopped pressing, the button comes up&lt;/li&gt;
&lt;li&gt; click —&amp;gt; click is needed though the down and up is triggered otherwise the click won’t be triggered&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  Options You Can Pass to the click function
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await page.locator('button').click({
  position: { x: 10, y: 5 }, // click at specific offset
  button: 'right', // 'left' | 'middle' | 'right'
  clickCount: 2,   // for double-click
  delay: 100,      // ms between mousedown and mouseup
  force: true,     // bypass checks
  modifiers: ['Alt', 'Shift'], // keyboard modifiers
  noWaitAfter: true// doesnt wait for navigation if click opens new page/elements
  timeout: 5000,   // override default timeout
  trial: true
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;p&gt;2.1 position&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Playwright calculates the clickable point:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It finds the center of the visible bounding box.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If position is specified, it uses that offset.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It ensures the point is not obscured by another element.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await locator.click({ position: { x: 10, y: 5 } });

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;p&gt;2.2 Right click/Left click / Middle click&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When right click is needed on a element, this will do the trick.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await page.locator('canvas').click({ button: 'right' }); // Right-click

await page.locator('canvas').click({ button: 'middle' }); // Middle-click

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;p&gt;2.3 Double click or more&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sometimes double click will trigger an event, this option can be used in that scenario.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await page.locator('text="Open File"').click({ clickCount: 2 });

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;p&gt;2.4 Delay&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;it's used to introduce a pause between the mousedown and mouseup events discussed in 1.4
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await page.locator('button').click({ delay: 500 }); // 500ms delay

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;p&gt;2.5 force&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;this option is used to bypass all actionability checks and force the click, even if the element is:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Not visible&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Not attached to the DOM&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Covered by another element&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Disabled&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Outside the viewport&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await page.locator('#hidden-button').click({ force: true });

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Sometimes, elements are technically present but:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Hidden by overlays or modals&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Slightly off-screen&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Temporarily disabled due to animations or transitions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using force: true allows you to click them anyway.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Be cautious about this - it skips safety checks.
&lt;/h2&gt;

&lt;p&gt;2.6 Shift+click&lt;/p&gt;
&lt;h2&gt;
  
  
  lets you simulate keyboard modifier keys being held down during the click — like Shift, Ctrl, Alt, or Meta (Cmd on Mac).
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await page.locator('.item').click({ modifiers: ['Shift'] }); 
//"Alt" | "Control" | "ControlOrMeta" | "Meta" | "Shift”

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;p&gt;2.7 NowaitAfter&lt;br&gt;
This is used to prevent Playwright from waiting for potential page navigations or asynchronous events that might be triggered by the click.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# and defaults to false
await page.locator('a#delayed-link').click({ noWaitAfter: true });
# will default to true in future releases
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;2.8 timeout&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;it controls How Long Playwright Waits for actionability checks&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you don’t specify timeout, Playwright uses the default timeout (usually 30 seconds).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When a element takes time to load and you want to extend or limit the timeout different from gloabl timeout then this can be used.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await locator.click({ timeout: 5000 }); // custom timeout
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;2.9 Trial Click&lt;br&gt;
You can simulate a click without actually clicking using trial: true. This is useful for checking if an element is clickable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await locator.click({ trial: true });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Common Pitfalls
&lt;/h2&gt;

&lt;p&gt;Some common failures and the causes&lt;br&gt;
Playwright throws a detailed error with suggestions and a trace.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7jj4ho90ydc500xcagmr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7jj4ho90ydc500xcagmr.png" alt=" " width="782" height="296"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;page.locator().click() is one of the most powerful and reliable ways to simulate user interaction in Playwright. By understanding its behavior, options, and best practices, you can write stable, maintainable, and robust automation scripts.&lt;/p&gt;

</description>
      <category>automation</category>
      <category>testing</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Event handling in playwright</title>
      <dc:creator>The Wise</dc:creator>
      <pubDate>Fri, 26 Sep 2025 12:21:12 +0000</pubDate>
      <link>https://dev.to/the_wise_06d8114f1ee73fe8/event-handling-in-playwright-3h1p</link>
      <guid>https://dev.to/the_wise_06d8114f1ee73fe8/event-handling-in-playwright-3h1p</guid>
      <description>&lt;p&gt;*&lt;strong&gt;&lt;em&gt;What is an event?&lt;/em&gt;&lt;/strong&gt;*&lt;/p&gt;

&lt;p&gt;An event is a signal that something has happened in the system or application — like a user clicking a button, a page loading, or a dialog appearing.&lt;/p&gt;

&lt;p&gt;An event represents a specific action or occurrence that you can listen for and respond to in your code.&lt;/p&gt;

&lt;p&gt;*&lt;strong&gt;&lt;em&gt;✅ Here is the list of events supported in the playwright&lt;/em&gt;&lt;/strong&gt;*&lt;/p&gt;

&lt;p&gt;Event Name  Description&lt;br&gt;
'close' Fired when the page is closed.&lt;br&gt;
'console'   Fired when the page logs a message to the console.&lt;br&gt;
'crash' Fired when the page crashes.&lt;br&gt;
'dialog'    Fired when an alert, confirm, prompt, or beforeunload dialog is triggered.&lt;br&gt;
'domcontentloaded'  Fired when the DOM content is fully loaded.&lt;br&gt;
'download'  Fired when a file download is initiated.&lt;br&gt;
'filechooser'   Fired when a file input is activated.&lt;br&gt;
'frameattached' Fired when a frame is attached to the page.&lt;br&gt;
'framedetached' Fired when a frame is removed from the page.&lt;br&gt;
'framenavigated'    Fired when a frame navigates to a new URL.&lt;br&gt;
'load'  Fired when the page finishes loading.&lt;br&gt;
'pageerror' Fired when a JavaScript error occurs.&lt;br&gt;
'popup' Fired when a new page (popup or tab) is opened.&lt;br&gt;
'request'   Fired when a network request is made.&lt;br&gt;
'requestfailed' Fired when a network request fails.&lt;br&gt;
'requestfinished'   Fired when a network request completes.&lt;br&gt;
'response'  Fired when a network response is received.&lt;br&gt;
'websocket' Fired when a WebSocket is created.&lt;br&gt;
'worker'    Fired when a web worker is created.&lt;/p&gt;
&lt;h2&gt;
  
  
  Let’s pick the event “dialog” for the demo
&lt;/h2&gt;
&lt;h2&gt;
  
  
  await promise
&lt;/h2&gt;

&lt;p&gt;Before the event occurs on the browser, we have to instruct the playwright to be ready to handle the event&lt;/p&gt;

&lt;p&gt;so the sequence is&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;store promise by using waitforevent method without await keyword&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;you do the action which triggers the popup&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;you wait for the stored promise to fulfil (captured in first step)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;you take action on the event.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

  // Start waiting for the dialog before triggering it
  const dialogPromise = page.waitForEvent('dialog');

  // Trigger the dialog (e.g., clicking a button that opens an alert/confirm/prompt)
  await page.getByText('Trigger Dialog').click();

  // Wait for the dialog to appear
  const dialog = await dialogPromise;

  // Accept the dialog
  await dialog.accept();

  // Dismiss the dialog (uncomment to use instead of accept)
  // await dialog.dismiss();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Promise.all
&lt;/h2&gt;

&lt;p&gt;(same as above but no need (await dialogPromise;) statement)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
// Start waiting for the dialog and trigger it at the same time
const [dialog] = await Promise.all([
  page.waitForEvent('dialog'),
  page.getByText('Trigger Dialog').click()
]);

// Accept the dialog
await dialog.accept();

// Dismiss the dialog (uncomment to use instead of accept)
// await dialog.dismiss();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ✅ page.on('dialog', callback) method
&lt;/h2&gt;

&lt;p&gt;Purpose: Listens for all dialog events continuously and performs the actions defined.&lt;/p&gt;

&lt;p&gt;Usage: Ideal when dialogs can appear multiple times during a test.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; // Set up a listener for dialog events
    page.on('dialog', async dialog =&amp;gt; {
      console.log(`Dialog message: ${dialog.message()}`);

      // Accept the dialog
      await dialog.accept();

      // Dismiss the dialog (uncomment to use instead of accept)
      // await dialog.dismiss();
    });

    // Trigger the dialog (e.g., clicking a button that opens an alert/confirm/prompt)
    await page.getByText('Trigger Dialog').click();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ✅ page.once('dialog', callback)
&lt;/h2&gt;

&lt;p&gt;Purpose: Listens for only the next dialog event &amp;amp; does whatever mentioned in the once block&lt;/p&gt;

&lt;p&gt;Usage: Cleaner than page.on when you expect just one dialog.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
    // Set up a one-time listener for the next dialog event
    page.once('dialog', async dialog =&amp;gt; {
      console.log(`Dialog message: ${dialog.message()}`);

      // Accept the dialog
      await dialog.accept();

      // Dismiss the dialog (uncomment to use instead of accept)
      // await dialog.dismiss();
    });

    // Trigger the dialog (e.g., clicking a button that opens an alert/confirm/prompt)
    await page.getByText('Trigger Dialog').click();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>playwright</category>
      <category>programming</category>
      <category>typescript</category>
      <category>automaton</category>
    </item>
    <item>
      <title>Playwright: A Modern Framework for Web Automation Testing</title>
      <dc:creator>The Wise</dc:creator>
      <pubDate>Fri, 19 Sep 2025 03:54:03 +0000</pubDate>
      <link>https://dev.to/the_wise_06d8114f1ee73fe8/playwright-a-modern-framework-for-web-automation-testing-4iak</link>
      <guid>https://dev.to/the_wise_06d8114f1ee73fe8/playwright-a-modern-framework-for-web-automation-testing-4iak</guid>
      <description>&lt;p&gt;Overview&lt;br&gt;
Playwright is an open-source automation framework developed by Microsoft, designed for end-to-end testing of modern web applications. Released in January 2020, it has quickly gained popularity due to its cross-browser, cross-platform, and cross-language capabilities.&lt;/p&gt;

&lt;p&gt;Key Features&lt;br&gt;
Cross-Browser Support: Automates Chromium (Chrome, Edge), Firefox, and WebKit (Safari).&lt;/p&gt;

&lt;p&gt;Multi-Language Support: Works with JavaScript, TypeScript, Python, Java, and .NET.&lt;/p&gt;

&lt;p&gt;Headless Mode: Enables fast, GUI-less testing ideal for CI/CD pipelines.&lt;/p&gt;

&lt;p&gt;Automatic Waiting: Waits for elements to be actionable, reducing flaky tests.&lt;/p&gt;

&lt;p&gt;Browser Contexts: Simulates multiple users with isolated sessions.&lt;/p&gt;

&lt;p&gt;Device Emulation: Tests responsive designs across various screen sizes.&lt;/p&gt;

&lt;p&gt;Network Interception: Mocks API responses and simulates network conditions.&lt;/p&gt;

&lt;p&gt;Built-in Debugging Tools: Includes codegen, trace viewer, and inspector.&lt;/p&gt;

&lt;p&gt;Architecture&lt;br&gt;
Playwright uses WebSockets for communication with browsers, unlike Selenium’s HTTP-based approach. This allows faster and more reliable interactions. Each test runs in a separate browser context, ensuring full isolation and faster execution.&lt;/p&gt;

&lt;p&gt;Advantages Over Other Frameworks&lt;/p&gt;

&lt;p&gt;Limitations&lt;br&gt;
No support for native mobile apps.&lt;/p&gt;

&lt;p&gt;Limited language support compared to Selenium.&lt;/p&gt;

&lt;p&gt;No support for legacy browsers like IE11.&lt;/p&gt;

&lt;p&gt;Getting Started&lt;br&gt;
To install and run Playwright:&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
