0

I am trying to open the view page source using playwright but cant proceed because of Target closed error. Below is my step or scenario:

  1. Access the page: https://www.orangehrm.com/
  2. And press Control U to access View page source.

Here is my code:

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

test('Keywords_Main', async ({ page }) => {
  await page.goto('https://www.orangehrm.com/');
   page.keyboard.press('Control+U');
  });

I am following the playwright documentation for keyboards functions but it seems that my code cant proceed to press the 'Control+U' : Below is the error that I encountered:

keyboard.press: Target closed

    test('Keywords_Main', async ({ page }) => {
     await page.goto('https://stage-unientwww.euwest01.umbraco.io/');
     page.keyboard.press('Control+U');
                      ^
   
     });
Sarah G
  • 21
  • 10
  • You can get the page source with `await page.content()` with JS disabled, or probably by navigating to `view-source:`. Why do you want to trigger the source with this particular key combination specifically? There might be a better way to achieve whatever you're trying to achieve. In any case, you probably meant to `await page.keyboard.press` which is often the cause of "Target closed" errors. – ggorlen Mar 11 '23 at 15:03
  • Does this answer your question? [Playwright error (Target closed) after navigation](https://stackoverflow.com/questions/61933492/playwright-error-target-closed-after-navigation) – ggorlen Mar 11 '23 at 15:52
  • I'm trying to access View page source then press Control F to find a keyword , now I can go to view page source but now it seems Control F is not working `await page.goto('view-source:https://www.unient.biz/teams/'); await page.keyboard.press('Control+F');` – Sarah G Mar 12 '23 at 01:30
  • What keyword you want to find? You should be able to just search it as a substring of the content. `(await page.content()).includes("your keyword")` (or `indexOf` if you want to know where it is rather than whether it exists. – ggorlen Mar 12 '23 at 02:49
  • seems like control f is not working in view page source, so Im looking another approach to verify the meta keywords – Sarah G Mar 13 '23 at 07:59
  • Which meta keyword? Sorry, but I can't help without a concrete statement of what you're expecting as output. Are you trying to select ``? If so, `page.locator('meta[name="keywords"]').getAttribute("content")` should work. – ggorlen Mar 13 '23 at 16:11
  • Should be answered in [your new question](https://stackoverflow.com/questions/75724006/playwright-tohaveattribute-is-not-working-when-checking-the-meta-keywords/75724504#75724504) now. The same code there should work for this page. – ggorlen Mar 13 '23 at 16:30

0 Answers0