gab*_*ans 29 javascript playwright
如何检索 Playwright 中页面的当前 URL?类似于browser.getCurrentUrl()
Protractor 中的东西吗?
eme*_*ery 24
以字符串形式获取当前页面的 URL(无需等待):
page.url()
Run Code Online (Sandbox Code Playgroud)
其中“page”是Page 类的对象。您应该已经有一个 Page 对象,并且有多种方法可以实例化它,具体取决于您的框架的设置方式: https: //playwright.dev/docs/api/class-page
它可以通过导入
import Page from '@playwright/test';
Run Code Online (Sandbox Code Playgroud)
或这个
const { webkit } = require('playwright');
(async () => {
const browser = await webkit.launch();
const context = await browser.newContext();
const page = await context.newPage();
}
Run Code Online (Sandbox Code Playgroud)
Him*_*waj 19
const {browser}=this.helpers.Playwright;
await browser.pages(); //list pages in the browser
//get current page
const {page}=this.helpers.Playwright;
const url=await page.url();//get the url of the current page
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
49736 次 |
最近记录: |