0

When I click on Copy Link hyperlink, link(url) is getting copied. I want to open new tab and past that copied url into the address bar?

How can I do that using Playwright?

I am using playwright with typescript.

In attached image, you can see copy link (hyperlink).

Thanks in advance.

I tried multiple ways to achieve it.

  • 1
    "I tried multiple ways to achieve it."--can you share those attempts? Thanks. – ggorlen Dec 13 '22 at 07:16
  • Instead of trying to paste the url into the browser address bar, wouldn't it be easier to just do a `await page.goto(url)` of the page from the new tab? – AJG Dec 13 '22 at 08:44
  • Please, provide the code you tried and the error you get – Jaky Ruby Dec 13 '22 at 16:09

1 Answers1

0

Try this:

test('test no 1', async ({ context }) => {
    await page.locator("your-locator").click(); //click is used because of a lack of auto-waits for innerText() (more info: https://playwright.dev/docs/actionability)
    const urlText = await page.locator("your-locator").innerText(); // save copied url
    const pageOne = await context.newPage();
    await pageOne.goto(urlText); //open new tab using copied url
})
1449
  • 21
  • 5
  • It's important to not just post code, but to also include a description of what the code does and why you are suggesting it. This helps others understand the context and purpose of the code, and makes it more useful for others who may be reading the question or answer. – DSDmark Dec 29 '22 at 18:02