-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add page convenience methods for textContent and getAttribute #2235
feat: add page convenience methods for textContent and getAttribute #2235
Conversation
This patch adds: - `page.innerText()` / `frame.innerText()` - `page.innerHTML()` / `frame.innerHTML()` - `page.textContent()` / `frame.textContent()` - `page.getAttribute()` / `frame.getAttribute()` Fixes microsoft#2143
docs/api.md
Outdated
@@ -1275,6 +1279,15 @@ Returns frame matching the specified criteria. Either `name` or `url` must be sp | |||
#### page.frames() | |||
- returns: <[Array]<[Frame]>> An array of all frames attached to the page. | |||
|
|||
#### page.getAttribute(selector, name[, options]) | |||
- `selector` <[string]> A selector to search for an element. If there are multiple elements satisfying the selector, the first will be checked. See [working with selectors](#working-with-selectors) for more details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"will be checked" is probably a copy-paste from somewhere 😄 Same in other methods.
docs/api.md
Outdated
- `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. | ||
- returns: <[Promise]<null|[string]>> | ||
|
||
Resolves to the `node.innerHTML`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We always resolve to elements, make this element.innerHTML
? Same in other methods.
src/page.ts
Outdated
return this.mainFrame().textContent(selector, options); | ||
} | ||
|
||
async innerText(selector: string, options?: types.TimeoutOptions): Promise<string | null> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can innerText or innerHTML be null?
Also, for textContent, would it be much more convenient to convert null into empty string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these all are actually always strings; casted.
src/frames.ts
Outdated
|
||
async innerText(selector: string, options: types.TimeoutOptions = {}): Promise<string> { | ||
return await this._retryWithSelectorIfNotConnected('innerText', selector, options, | ||
(handle, deadline) => handle.innerText() as Promise<string>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we update ElementHandle.innerText() and ElementHandle.innerHTML() to return string as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/frames.ts
Outdated
@@ -730,6 +730,26 @@ export class Frame { | |||
(handle, deadline) => handle.focus()); | |||
} | |||
|
|||
async textContent(selector: string, options: types.TimeoutOptions = {}): Promise<string> { | |||
return await this._retryWithSelectorIfNotConnected('textContent', selector, options, | |||
(handle, deadline) => handle.textContent() as Promise<string>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... We should have the same return type here and in ElementHandle.textContent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
This patch adds:
page.innerText()
/frame.innerText()
page.innerHTML()
/frame.innerHTML()
page.textContent()
/frame.textContent()
page.getAttribute()
/frame.getAttribute()
Fixes #2143