astral icon indicating copy to clipboard operation
astral copied to clipboard

Is it possible to select file for input elements?

Open ooker777 opened this issue 1 year ago • 3 comments

I have an HTML input element whose type is file:

<input accept="image/*, image/heic, image/heif" aria-label="Add photo" class="bb bc" type="file" name="file1">

Can I select a file to submit for it? It doesn't seem to be available for ElementHandle. In that case, can you add this one?

ooker777 avatar Nov 12 '24 09:11 ooker777

Do you have an example of how you would expect this to work?

lino-levan avatar Nov 12 '24 23:11 lino-levan

My goal is to automate posting Facebook posts. There is a problem of clicking the "What's on your mind" input, as it seems that the selectors change every time the page is reloaded. I then use the mobile version m.facebook.com. I want to upload image for the posts. Is it possible? image

ooker777 avatar Nov 13 '24 15:11 ooker777

So if I'm reading this right, is the problem just that you can't select it by class because the classes keep shuffling?

If that's the case, other properties are accessible from within CSS selectors that should help you here. The selector syntax for this is [attribute="value"]. You should be able to just grab it by type or aria-label this way.

You can add it to an element the way you would with classes or pseudo-selectors -- input[type="file"] for instance -- but you don't strictly have to, and it doesn't sound like you'd need to specify that for the use case you're describing.

chaosharmonic avatar Jan 05 '25 23:01 chaosharmonic