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

@devtools: Enable file uploads by changing input elements' value #5347

Merged
merged 7 commits into from May 2, 2020
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/devtools/src/commands/elementSendKeys.js
@@ -1,4 +1,5 @@
import { getStaleElementError } from '../utils'
import path from 'path'

export default async function elementSendKeys ({ elementId, text }) {
const elementHandle = this.elementStore.get(elementId)
Expand All @@ -9,7 +10,15 @@ export default async function elementSendKeys ({ elementId, text }) {

await elementHandle.focus()
const page = this.getPageHandle()
await page.keyboard.type(text)
const tagName = await (await elementHandle.getProperty('tagName')).jsonValue()
const type = await (await elementHandle.getProperty('type')).jsonValue()

if(tagName === 'INPUT' && type === 'file'){
const paths = (text || '').split('\n').map(p => path.resolve(p))
await elementHandle.uploadFile(...paths)
} else {
await page.keyboard.type(text)
}

return null
}