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
3,211
questions
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 ...
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')
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 ...
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 ...
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 ...
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 {
...
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?
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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, ...
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 });
...
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?
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 ?
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?
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 ...
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:
...
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....
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 ...
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', () => {
...
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 ...
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:...
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 ...
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(), ...
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 ({ ...
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 ...
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.
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/...
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 ...
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?
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"]', './...
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
...
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?
====================...
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.
...
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 ...
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'],
...
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....
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 ...
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 ...
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 ...
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 ...
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. ...
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]....
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 ...
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 ...
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 (...