Skip to main content

Questions tagged [playwright]

Playwright is a framework for web testing and automation. It allows testing Chromium, Firefox and WebKit, Chrome, and Microsoft Edge with a single API. Playwright's API is similar to Puppeteer, but with cross-browser support and Python, Java, and .NET bindings, in addition to Node.js.

playwright
Filter by
Sorted by
Tagged with
52 votes
12 answers
135k views

How to check if an element exists on the page in Playwright.js

I am using playwright.js to write a script for https://target.com, and on the page where you submit shipping information, it will provide the option to use a saved address if you have gone through the ...
cole's user avatar
  • 523
44 votes
6 answers
82k views

Getting value of input element in Playwright

How do I return the value of elem so that I can verify that it is in fact 1? const elem = await page.$('input#my-input') await elem.fill('1')
JakeDK's user avatar
  • 1,196
44 votes
7 answers
53k views

How can I assert that an element is NOT on the page in playwright?

I'm testing a website that includes a logo, and I want to make sure the logo does not appear on some pages. How can I assert that an element does NOT exist? I checked the Playwright assertions ...
Patrick Kenny's user avatar
33 votes
2 answers
14k views

What is the difference between testing on Safari vs Webkit?

I'm looking at writing some E2E tests using Playwright. I can see that the library allows tests to be run against Chromium, Firefox and Webkit. My understanding is that Webkit is the underlying engine ...
user1087943's user avatar
30 votes
5 answers
86k views

Playwright error (Target closed) after navigation

I'm trying something really simple: Navigate to google.com Fill the search box with "cheese" Press enter on the search box Print the text for the title of the first result So simple, but I can't get ...
Daniel Hernández Alcojor's user avatar
29 votes
7 answers
97k views

How to get a collection of elements with playwright?

How to get all images on the page with playwright? I'm able to get only one (ElementHandle) with following code, but not a collection. const { chromium } = require("playwright"); class Parser { ...
CoderDesu's user avatar
  • 817
29 votes
4 answers
60k views

Get current page url with Playwright Automation tool?

How can I retrieve the current URL of the page in Playwright? Something similar to browser.getCurrentUrl() in Protractor?
gabogabans's user avatar
  • 3,465
25 votes
4 answers
66k views

How to pause the test script for 3 seconds before continue running it? Playwright

I'm running a test called create admin. The test will first create admin, then check if the admin was created successfully. In the script, I have a part of code where I want to wait for 3 seconds ...
jialeee17's user avatar
  • 771
25 votes
4 answers
48k views

How can I select an element by Id?

I wonder how I can access an element by ID. I want to submit a form. await page.click("id= 'next'"); --> not possible await page.getByRole('button', { id: 'next' }).click(); --> does ...
Johannes Schacht's user avatar
24 votes
3 answers
55k views

How to get an element's attribute in a Playwright test?

I'm trying to get an element's attribute in a test. My test looks like this: test(`Should be at least 5 characters long`, async({ page }) => { await page.goto('http://localhost:8080'); const ...
Dev's user avatar
  • 1,125
24 votes
22 answers
33k views

Playwright VSCode gives `No tests found` message

I've installed the Playwright vscode extension but when I go to the testing area I get a "No tests have been found in this workspace" message. But when I run $> playwright test on the CLI ...
Jeanluca Scaljeri's user avatar
22 votes
3 answers
59k views

How to wait for requests and validate responses using playwright?

This is my first time using playwright and I can't figure out how to wait for requests and validate responses. I've been using cypress for a quite a long time, and it was pretty easy to manage network ...
Vladimir Krygin's user avatar
22 votes
7 answers
81k views

Playwright: how to wait until there is no animation on the page?

I'm trying to figure out how to check whether the page has fully loaded in Playwright. await page.waitForLoadState('networkidle'); doesn't always work for me on Javascript-heavy sites. I've resorted ...
eeeeeeeeeeeeeeeeeeeeeeeeeeeeee's user avatar
20 votes
7 answers
82k views

Check if element is visible in Playwright

I'm using Playwright 1.15.2 for testing and facing a problem with elements' visibility. I want to check if a modal is visible on screen so I can close it. The modal starts with display:none and turns ...
JeanCHilger's user avatar
20 votes
5 answers
45k views

How to use installed version of chrome in Playwright?

I want to use chrome instead of chromium. I can achieve the same in puppeteer by providing executable path. In playwright it doesn't work as browser type argument supports only 'chromium, webkit, ...
Rajesh G's user avatar
  • 563
19 votes
3 answers
36k views

Playwright JS - How to globally define/change timeout if element/selector not found?

Basically I want playwright to wait for each element 5 seconds if element not found. There is a way to change timeout individually as given below: await page.waitForSelector('h1', { timeout: 5000 }); ...
Mairaj Ali's user avatar
19 votes
4 answers
33k views

Playwright tests - using variable from .env file

I've got Playwright test written using TypeScript and I would like to use variables from .env in my test file, how can I do that?
MichalG's user avatar
  • 351
19 votes
6 answers
87k views

Playwright - how to wait for an element to be clickable

like in selenium, do we have option in Playwright to wait for an element to be clickable ?
sumit's user avatar
  • 231
18 votes
3 answers
18k views

How to achieve browser resizing in run time using playwright? in a e2e test run

We have in protractor like: browser.driver.manage().window().setSize( width - 30, height ); How to achieve this in playwright?
Sangeetha's user avatar
  • 211
16 votes
7 answers
43k views

Playwright auto-scroll to bottom of infinite-scroll page

I am trying to automate the scraping of a site with "infinite scroll" with Python and Playwright. The issue is that Playwright doesn't include, as of yet, a scroll functionnality let alone ...
alex_bits's user avatar
  • 712
16 votes
3 answers
35k views

Ignore SSL errors with playwright code generation

I am using the jest-playwright library (https://github.com/playwright-community/jest-playwright) to perform end-to-end testing. In the jest.config.js file you can set an option to ignore SSL errors: ...
kingkoen's user avatar
  • 161
16 votes
5 answers
22k views

How to read a textbox value from a playwright

I have input text field on the page with id "email30" and I am trying to read it's value from Playwright let dd_handle = await page.$("#email30"); let value = await dd_handle....
Paresh Varde's user avatar
  • 1,124
16 votes
4 answers
17k views

In Playwright, how to pass a baseUrl via command line so my spec files dont have a hardcoded url for the app I am testing?

In Protractor, I am currently passing a flag in the command line that indicates what my URL is for the app I am testing. And now we are switching to Playwright, I want to do something similar. Since ...
Kumar's user avatar
  • 335
15 votes
6 answers
25k views

Run grouped tests sequentially using Playwright

I'm using Playwright with nodejs and I have grouped a couple of tests together like this import { test, expect } from '@playwright/test'; test.describe('Add a simple invoice test', () => { ...
Amrou's user avatar
  • 421
15 votes
5 answers
31k views

Is there a way to iterate over a <li> list in Playwright and click over each element?

I'm trying to iterate over a list of dynamic elements with Playwright, I've tried a couple of things already, but none have been working: await this.page.locator('li').click(); const elements = await ...
Gabriel Costa's user avatar
15 votes
4 answers
28k views

Playwright before each for all spec files

I am very new to Playwright. Due to my test suites, I need to login into my application before running each test. Inside a single spec file that is easy, I can simply call test.beforeEach. My issue is:...
Pelicer's user avatar
  • 1,544
15 votes
3 answers
54k views

How to wait for JavaScript to finish in playwright

I am testing UI with Playwright and JavaScript. My code find an input element that can sometimes be a drop down, sometimes a text and sometimes a date. To handle this I enter value with 2 steps. First ...
Jacob's user avatar
  • 1,205
15 votes
2 answers
36k views

How to add custom headers in Playwright

headers["user-agent"] = fakeUa(); console.log(fakeUa()) let firstReq = true; page.route('**/*', route => { const request = route.request() //console.log(request.url(), ...
Amna Arshad's user avatar
15 votes
2 answers
25k views

How to console.log in playwright

I want to log one of the variables inside the playwright test case but am unable to load the log in developer tools console as I am using a page.on() function test('largest contentful paint', async ({ ...
KnightCrawler's user avatar
14 votes
6 answers
41k views

How to open the new tab using Playwright (ex. click the button to open the new section in a new tab)

I am looking for a simpler solution to a current situation. For example, you open the google (any another website) and you want BY CLICK on the button (ex. Gmail) - open this page in the new tab using ...
Olya's user avatar
  • 287
14 votes
2 answers
6k views

Disable Javascript in Playwright

Is it possible to define a browser with Javascript disabled to simulate how a crawler would view a page? There should be an option that can be passed.
Dietrich's user avatar
  • 161
14 votes
3 answers
29k views

How to make CONDITIONAL STATEMENTS using SELECTORS on PLAYWRIGHT? [duplicate]

I need some help to make conditional statements using Playwright tests. I have a given selector, let's say a button, and I need to write a conditional statement like this: if (selector is not present/...
Ciccios_1518's user avatar
14 votes
16 answers
41k views

playwright 'no tests found.' on simple copy of example.spec.ts

I have just installed playwright (v1.18.1) to try it out (Windows 11) and I feel like something is wrong. I can run the example.spec.ts script fine, but if I copy that file and then try to run the ...
abe1432181's user avatar
  • 1,173
14 votes
5 answers
14k views

Can I set the date for playwright browser

When I write tests to run in playwright, I would like to be able to set the date that the browser believes it to be at the start of the test. Is there a way to achieve this using playwright?
Billy Moon's user avatar
  • 58.5k
13 votes
4 answers
19k views

Playwright: Upload files from non-input element that cannot be used page.setInputFiles?

I'm working on uploading files through non-input HTML tag on Playwright. For example, you can use setInputFiles like this, and this works: await page.setInputFiles('input[type="file"]', './...
ー PupSoZeyDe ー's user avatar
13 votes
3 answers
8k views

missing dependencies when running playwright in docker

I tried to run the playwright in docker but got this error: browserType.launch: Host system is missing dependencies! Missing libraries are: libvpx.so.6 libicui18n.so.66 libicuuc.so.66 ...
Dustin Le's user avatar
  • 131
13 votes
1 answer
16k views

Playwright using JS ,getting - page.goto: net::ERR_ABORTED; maybe frame was detached? ===== logs ====== navigating to "URL", waiting until "load"

Trying to implement Playwright with java script to one of my new projects using POM framework but getting this error as below page.goto: net::ERR_ABORTED; maybe frame was detached? ====================...
vinayanth . k's user avatar
13 votes
2 answers
9k views

Puppeteer: How can I wait until a list is closed? How can I wait until an element is disappeared from the DOM?

Сase: There is a list in which you need to select an item, then it closes. When you click on another item the list does not have time to close. Finally there is one more click on another list element. ...
Oleksiy's user avatar
  • 131
12 votes
2 answers
11k views

Can you run multiple tests in one browser context Playwright Javascript?

Is it possible to run multiple tests in one browser window for playwright/test? currently it will hit browser.close(); after every test even though they are testing on the same page which puts a lot ...
el_nuggs's user avatar
  • 131
12 votes
3 answers
9k views

How do I access playwright test runner project info in a test?

I'm writing a test to register users on my site. Using @playwright/test, I have defined several different projects in playwright.config.ts: { name: 'iPhone 12 Pro', use: devices['iPhone 12 Pro'], ...
Patrick Kenny's user avatar
12 votes
5 answers
20k views

Cannot figure out how to wait for text in input value

Scenario: I need to wait for some specific text to load on the page, the issue im experiencing is that the text is the value of an input box and this value is the last thing on the page to load/appear....
getCritical's user avatar
12 votes
3 answers
31k views

Playwright how to wait for locator that matches multiple elements to not be visible

I am trying to wait for an element that indicates a page is still loading, and exists on the page multiple time, to not be visible (think table with loading data placeholders). Playwright ...
bee-anchor's user avatar
12 votes
5 answers
17k views

Using Playwright, page.url() is getting a previous url instead of the current url

I'm testing the navigation on our website using expect(page.url()).toContain('/nav');. When walking through the code I can clearly see that we hit that url string after the click. I've tried putting ...
CamdyCorn's user avatar
  • 151
12 votes
6 answers
26k views

playwright find child element(s) within locator

I'm trying to write a function to find child(ren) element(s) within a locator something like: async findElements(locator: Locator){ return locator.querySelector(some/xpath/or/css); } However, I'm ...
Peter Huang's user avatar
  • 1,104
11 votes
7 answers
48k views

Add cookies in playwright test

No matter what I do I get an error (either X.cookies is not a function or X.addCookies is not a function). I tried with context, page.context. browserContext etc. and it always ends up in the same way ...
ugabuga77's user avatar
  • 731
11 votes
1 answer
15k views

Updating NextJS/playwrights nodejs version?

My build on Vercel has started failing due to Playwright's depreciated Node.js version: Error: Node.js version 12.x is deprecated. Deployments created on or after 2022-08-09 will fail to build. ...
meds's user avatar
  • 22.6k
11 votes
4 answers
26k views

Playwright get cookie

I need to get a JSSESSIONID cookie from one page and pass it to another. But when I try to fetch cookie with a playwright I got an empty array. Any ideas? const browser = await playwright[browserType]....
dusan's user avatar
  • 111
11 votes
2 answers
39k views

How to select a dropdown option using playwright in JavaScript?

I would like to select "All" option from the below DOM using Playwright JS, and I have tried page.selectOption('select#rows per page', '-1'); and page.selectOption('id=mui-55656', '-1'); to ...
gbackmania's user avatar
11 votes
3 answers
15k views

Playwright stealth [closed]

I have been using puppeteer for a while, but decided to convert to playwright. In puppeteer, there was a plugin puppeteer-extra-stealth which was able to hide headless chrome and websites did not ...
A.Bokizh's user avatar
  • 145
11 votes
2 answers
13k views

How to run particular file with Playwright?

I have multiple test files in a specific folder with extension spec.ts. How I can run a particular file with Playwright? Currently for configuration is set as the test folder and will run all files (...
Gaj Julije's user avatar
  • 1,983

1
2 3 4 5
65