textContent(selector[, options])
警告
请改用基于定位器的
locator.textContent([options])
。
返回元素的 element.textContent
。
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
selector | string | '' | 用于查找元素的选取器。如果存在多个满足条件的元素,将使用第一个。 |
options | object | null | |
options.strict | boolean | false | 当为 true 时,调用要求选取器解析为单个元素。如果给定的选取器解析为多个元素,调用将抛出异常。 |
options.timeout | number | 30000 | 最大时间,单位为毫秒。传递 0 以禁用超时。默认值会被 BrowserContext 或 Page 上的 setDefaultTimeout 选项覆盖。 |
返回值
类型 | 描述 |
---|---|
Promise<string | null> | 一个 Promise,它会使用选取器的文本内容或 null 来 fulfilled。 |