-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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]: Ability to check wait for value on a input #1444
Comments
Thanks for the suggestion! I wonder if you were able to use page.waitForSelector('text=Foo') It is possible to have a narrower criteria, like wait for a page.waitForSelector('css=div >> text=Foo') I'm trying to learn if there are reasons this wouldn't work for your needs? |
Thanks for the response this The problem area i'm working in is shadow dom, im using the awesome custom selectors feature to register a selector, like so: https:/Georgegriff/query-selector-shadow-dom#playwright
|
Yes, the Also we fixed an issue in #1169, and it might be worth trying against |
Thanks for the info, i'll experiment and get back to you |
So i took a look, this is mostly fantastic for text. Where it runs into problems is |
Can you elaborate on this please? If the |
Value on But dom elements also have For Hopefully the gif shows how attributes in the dom aren't always reflected to their properties and vice versa. If i do a setAttribute on value it does nothing, if i do a .value updates in the UI but does not update the And because the attribute |
I can do this in user land with a custom engine by copying what your code does for these, but might be trickier playwright/src/injected/injected.ts Line 24 in 9826fd6
|
Related issue someone else asking for this: #1427 |
For reference he's a naive implementation, doesn't work as well as text built in engine because it relies on a previous compound selector to have found an element for it to succeed. const createValueEngine = () => {
return {
// Creates a selector that matches given target when queried at the root.
// Can return undefined if unable to create one.
create(root, target) {
return null;
},
// Returns the first element matching given selector in the root's subtree.
query(root, selector) {
if (!root) {
return null;
}
return "" + root["value"] === selector;
},
// Returns all elements matching given selector in the root's subtree.
queryAll(root, selector) {
if (!root) {
return null;
}
return "" + root["value"] === selector;
}
};
};
await playwright.selectors.register("value", createValueEngine);
// example usage input.my-cvlass >> value="User input value" |
Thanks @Georgegriff! I think #1427 captures this issue, and I'm going to close this as a duplicate for now. Feel free to reopen if I've missed something. |
Hey @arjunattam the PR you mentioned does only deal with values on submit buttons. Having some kind of My use caseWe are populating input fields asynchronously and I would like to check if they are fully loaded by checking for them in playwright. <label for="title">Title</label>
<input id="title" name="title" /> // Pseudo version of our update function
const response = await fetch("/title-data");
const title = await response.text();
const titleInput = document.querySelector("#title");
titleInput.value = title; // Current solution in playwright
page.waitForFunction(({expectedTitle}) => {
const titleInput = document.querySelector("#title");
return titleInput.value === expectedTitle;
}, { expectedTitle: "my-input-value" }) That works, but I do not have access to the full power of playwright. For example it would be hard to select the input by its label text. Also being able to use the playwright selector engine instead of Possible solutionsSo I was hoping for a selector like // Matches input that has label text of `Title` and an input value of `my-input-value`
await page.waitForInputValue(`"Title"`, "my-input-value"); A different approach would be an extension to the text selector. E.g. // Matches input that has label text of `Title` and an input value of `my-input-value`
await page.waitForSelector(`"Title" >> value="my-input-value"`) Other
|
This worked okay for me but I would make it a function and add a time out: while(await page.$eval('span.class', (el) => !el.textContent?.includes('some inner text'))); |
How to use same for Playwright with java? |
It would be great if Playwright had something similar to CodeceptJS methods:
or
I guess this could be in a form similar to
waitForProperty
? which waits for an element to exist and waits for a property of key and valuee.g.
waitForProperty(selector, "innerText", "Foo",{timeout})
waitForProperty(selector, "value", "bar",{timeout})
The text was updated successfully, but these errors were encountered: