Skip to content
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

Merged
merged 7 commits into from
May 19, 2020

Conversation

aslushnikov
Copy link
Collaborator

This patch adds:

  • page.innerText() / frame.innerText()
  • page.innerHTML() / frame.innerHTML()
  • page.textContent() / frame.textContent()
  • page.getAttribute() / frame.getAttribute()

Fixes #2143

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.
Copy link
Contributor

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`.
Copy link
Contributor

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> {
Copy link
Contributor

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?

Copy link
Collaborator Author

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>);
Copy link
Contributor

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?

Copy link
Collaborator Author

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>);
Copy link
Contributor

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@aslushnikov aslushnikov merged commit f24696b into microsoft:master May 19, 2020
@aslushnikov aslushnikov deleted the expose-extra-methods branch May 19, 2020 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] expose textContent, innerText, getAttribute on page/frame
2 participants