Page.locator() 方法
🌐 Page.locator() method
locator(): Locator<NodeFor<Selector>>
为提供的选择器创建一个定位器。有关详细信息和支持的操作,请参见 Locator。
🌐 Creates a locator for the provided selector. See Locator for details and supported actions.
语法
🌐 Signature
class Page {
locator<Selector extends string>(
selector: Selector,
): Locator<NodeFor<Selector>>;
}
参数
🌐 Parameters
范围 🌐 Parameter | 类型 🌐 Type | 描述 🌐 Description |
|---|---|---|
selector | 选择器 🌐 Selector | selector 用于查询页面。CSS selectors 可以按原样传递,Puppeteer-specific selector syntax 允许通过 text、a11y role and name 和 xpath 查询,并且可以 combining these queries across shadow roots。或者,你可以使用 prefix 指定选择器类型。 |
返回:
locator(): Locator<Ret>
为提供的函数创建一个定位器。详情和支持的操作请参见 Locator。
🌐 Creates a locator for the provided function. See Locator for details and supported actions.
语法
🌐 Signature
class Page {
locator<Ret>(func: () => Awaitable<Ret>): Locator<Ret>;
}
参数
🌐 Parameters
范围 🌐 Parameter | 类型 🌐 Type | 描述 🌐 Description |
|---|---|---|
func | () => Awaitable<Ret> |
返回:
Locator<Ret>