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

[Feature] innerText not defined in evaluate context #1237

Closed
thernstig opened this issue Mar 5, 2020 · 3 comments
Closed

[Feature] innerText not defined in evaluate context #1237

thernstig opened this issue Mar 5, 2020 · 3 comments

Comments

@thernstig
Copy link
Contributor

    const foo= await page.waitForSelector('text="Something"');
    expect(await foo.evaluate(el => el.innerText)).toBe('Something');

Here innerText is not a type (if you e.g. use VS Code for autocompletion) whereas textContent is. It would be nice to add innerText into the TypeScript definitions.

(On a side-note it is quite verbose to get some text then assert on it, as above, but I don't think there is a nicer way (one-liner) for this?)

@aslushnikov
Copy link
Collaborator

Here innerText is not a type (if you e.g. use VS Code for autocompletion) whereas textContent is. It would be nice to add innerText into the TypeScript definitions.

cc @JoelEinbinder - can we actually do this?

On a side-note it is quite verbose to get some text then assert on it, as above, but I don't think there is a nicer way (one-liner) for this?

@thernstig yeah, no one-liner here. You can use page.waitFor to cut a little on the number of characters you use

@JoelEinbinder
Copy link
Contributor

#1166 fixes a lot of case like this, but I believe this actually working as intended. innerText does not exist on SVGElements, so you can't rely on it here unfortunately. If you know you are getting an HTMLElement, you can cast it with typescript or in js with JSDoc:

/** @type {playwright.ElementHandle<HTMLElement>} */
const foo = await page.waitForSelector('text="Something"');

@thernstig
Copy link
Contributor Author

thernstig commented Mar 6, 2020

@JoelEinbinder @alukyan This might be of interest. The above case was in regards to waitForSelector. Changing it to waitFor (with a string like above as input), it gives no autocompleteion at all for the el.. Is that "fixable"?

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

No branches or pull requests

3 participants