Comments (14)
"type" is done as
page.focus(selector)
page.type(text)
How does fill differ from setValue? Fill would work on contenteditable?
from puppeteer.
@JoelEinbinder How would you feel about the
page.type(selector, text)
This looks reasonable to me because it's unlikely one would ever use page.type
without page.focus
in your scenario.
It would also align with api of other similar libraries, e.g. nightmare.js's type
from puppeteer.
As per discussion with @JoelEinbinder and @paulirish:
// We need this FOR SURE:
page.click('#selector');
page.type('#selector', 'heyo')
page.type(Page.FOCUSED_ELEMENT, 'heyo') // type into focused element
// This looks promising:
page.mouse.move(x, y);
page.mouse.press({
clickCount: 1 // NOONE UNDERSTANDS EXCEPT JOEL
button: 'right'
});
page.mouse.move(x2, y2);
page.mouse.release('left')
// Some thoughts on touch API which is not ready:
var touch = page.touch.create(x, y);
// var touch2 = page.touch.create(x2, y2);
touch.down();
touch.move();
touch.up();
from puppeteer.
We could do page.submit('name')
to submit a form of the given name. This would be a shortcut to executing document.forms[name].submit()
in the browser. It would mean the form needs to be named for the quick access, but super useful still. Or if we wanted to be verbose with it due to the limitation on naming page.submitFormByName(<String>)
.
from puppeteer.
@Garbee the current approach for form submitting would be
page.$('form.thisone', e => e.submit());
I kinda prefer sticking to selectors for grabbing things. (If names were first-class then we'd probably have page.type(inputelementName, 'text')
)
I think right now we should skip adding a submit() method just to clarify that there's ZERO magic behind it.
from puppeteer.
Yea, names aren't first-class all the time. Only within the scope of document.forms
and then FormNode.elements
. Beyond that most of the time they're just another attribute. That's where the more verbose submitFormByName
comes in handy, it is clear that the form is named what is provided. No magic and only taking advantage of what the document already provides (even though it admittedly is lesser-used by developers.)
Best avoid introducing names in non-specific methods though, as the name could easily be a custom registered element name with Custom Elements. Then things get murky for people if the method were as simple as submit
.
from puppeteer.
I'm unclear if or how this would be different from
page.$('form[name="hello"]', f => f.submit());
Is there magic behavior with names I'm not taking into account?
from puppeteer.
It's not different execution in the end, it's just a cleaner way to handle submitting a form when it is named. It saves developers from constantly needing to write out the lookup and submit execution when writing tests to their web applications primarily. Which can add up to a good chunk of re-use in apps with a lot of forms.
from puppeteer.
I think I'd rather someone write their own helper
function submitForm(name) { page.$('form[name="' + name + '"]', f => f.submit()) }
I see the value in things like nightmare's .check
and .uncheck
, where it sets the value and dispatches an event quickly. Right now I expect a puppeteer method to send all the proper events and trigger every side effect of a user performing the action. The existence of javascript-only methods would cause me to not trust the api as much, and I'd end up looking at the source code to see if I should be doing a better job. I am probably more paranoid than your average developer though.
Maybe we can have a form helper object that has these methods, and states that it's mission is to work as quickly as possible. Or a separate project that implements the nightmare api.
from puppeteer.
In all of the scenarios we've tried, we didn't have a need for either page.fill
or page.setValue
. No one is also especially enthusiastic about this api, closing for now.
from puppeteer.
@aslushnikov I agree that page.fill
is not really necessary, specially considering that's pretty much what page.type
does nowadays. However a different API could make existing code much more concise.
CasperJS for instance, implements these helper methods quite conveniently:
fill(String selector, Object values, Boolean submit)
locates by input namefillSelectors(String selector, Object values, Boolean submit)
locates by CSS selectorsfillLabels(String selector, Object values, Boolean submit)
locates by input labelsfillXPath(String selector, Object values, Boolean submit)
locates by XPath selector
It abstracts the API interaction needed depending on the element type:
this.fill('form#contact-form', {
'subject': 'I am watching you', // Text
'content': 'So be careful.', // Text
'civility': 'Mr', // Radio / Select
'name': 'Chuck Norris', // Text
'email': '[email protected]', // Text
'cc': true, // Checkbox
'attachment': '/Users/chuck/roundhousekick.doc', // File
}, true);
I'm tempted to overload Page
with a custom implementation of these methods, but I was thinking that it could also be beneficial to others if they were part of PPTR core. Is there any interest in this?
from puppeteer.
I'm tempted to overload Page with a custom implementation of these methods, but I was thinking that it could also be beneficial to others if they were part of PPTR core. Is there any interest in this?
@alixaxel thanks for reaching out. I'd rather have these methods as a third-party.
from puppeteer.
@aslushnikov Cool, thanks.
Do you happen to know of any third-party project that demonstrates how to extend PPTR in a good way?
I'm currently doing something like the following, but somehow it feels hackish...
let Super = 'lib/Page';
try {
new Function('async () => {}')();
} catch (error) {
Super = `node6/${Super}';
}
Super = require(`puppeteer/${Super}`);
Super.prototype.fill = function (...) {
};
from puppeteer.
I'm currently doing something like the following, but somehow it feels hackish...
@alixaxel indeed, a little hackish. Unfortunately, I can't suggest any nicer approach.
from puppeteer.
Related Issues (20)
- [Bug]: Lost connection is not detected if no messages are being sent over WebSocket HOT 6
- [Bug]: Puppeteer click don't fail when actual element is overlapped HOT 5
- [Feature]: `@puppeteer/ng-schematics:builder` should support setting tsconfig.json, using path aliases, replacing environment.ts and not starting the dev-server HOT 2
- [Bug]: Request Interceptor weird behaviour HOT 4
- [Bug]: Unable to bundle puppeteer script with wepack HOT 2
- [Feature]: Inserting a Audio and video Stream HOT 2
- PDF export error for chart and HTM amchart5 HOT 1
- [Bug]: Stuck at puppeteer.connect() HOT 2
- [Bug]: Even your example code is not working - SyntaxError: Cannot use import statement outside a module HOT 1
- [Feature]: Inserting a Audio and video Stream
- "[network.spec] network Page.authenticate should work" test is flaky HOT 1
- [Bug]: Browser gets disconnected in Docker without any errors HOT 28
- [Bug]: Failed to launch the browser process!\nchrome_crashpad_handler: --database is required HOT 2
- Docs: the index page for docs should not be a readme.md
- [Feature]: Accessing WebRTC peerConnection in puppeteer
- Force pushing to default branch HOT 1
- [Bug]: ERROR in DIGITALOCEAN APPLICATION PLATFORM HOT 2
- [Bug]: when accessing browser.targets() I don't get info about _targetInfo which have property like _targetInfo.title , _targetInfo.type... HOT 2
- [Bug]: Opening the extension popup.html using will return new empty popup without any data how to get popup.html within the context of a specific tab/website HOT 4
- [Bug]: Background is pink when using background: repeating-linear-gradient HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from puppeteer.