Hi!
I have noticed that on two different laptops there is a difference in the behavior of page.keyboard.press('Enter')
depending on how the code is executed. If I execute the code using node index.js
I get a different behaviour, I get a line break (the wrong one) compared to when I execute the code using the Code Runner extension on VS Code, which submits a form e.g. (the correct behaviour).
The setup that I did:
mkdir try_playwright
cd try_playwright
npm init -y
Added in the package.json
: "type": "module"
Then:
npm install playwright
I go to VS Code, create a file index.js
and try this bit of code:
import { chromium } from 'playwright';
const browser = await chromium.launch({ headless: false });
const page = await browser.newPage();
await page.goto('https://google.com/');
await page.click('button:has-text("I agree")');
await page.type('textarea[title="Search"]', 'hello world');
await page.keyboard.press('Enter');
await page.waitForTimeout(10000);
await browser.close();
So I have tried this on two configurations:
Recap of the behaviours:
node index.js
command on terminal: types "hello world" in the search bar and then goes to a new line.Notes:
await page.click('button:has-text("I agree")');
is only useful is you're in EU. If your browser is in a different language, you should change the "I agree".This thread is trying to answer question "Why does the behavior of ```page.keyboard.press('Enter')``` differ depending on how the code is executed?"
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].