【问题标题】:How to check page in new tab in Playwright (C#)如何在 Playwright (C#) 的新标签页中查看页面
【发布时间】:2023-01-21 00:22:22
【问题描述】:

我想创建测试

  1. 使用鼠标中键单击元素
  2. 验证新标签页中的内容

    我知道如何创建新的浏览器上下文,但我不知道如何切换到新页面。 感谢您提前提供任何帮助。

【问题讨论】:

    标签: playwright playwright-sharp playwright-dotnet


    【解决方案1】:

    您可以使用 ElementHandle.click() 方法模拟鼠标单击特定元素。

    const browser = await playwright.chromium.launch();
    const page = await browser.newPage();
    
    // Navigate to a web page
    await page.goto('https://www.example.com');
    
    // Find the element that links to a new webpage
    const linkElement = await page.$('a[href="https://www.example.com/new-page"]');
    
    // Simulate a mouse click on the element
    await linkElement.click()
    

    【讨论】:

      猜你喜欢
      • 2012-08-12
      • 2022-01-26
      • 1970-01-01
      • 2019-09-09
      • 2019-12-28
      • 1970-01-01
      • 2022-08-18
      • 2021-03-12
      • 1970-01-01
      相关资源
      最近更新 更多