我正在尝试在android webview的depop上自动填写表单。目标是从url或内部存储上传图像,但不需要用户手动完成。像vendoo或listperfectly这样的chrome扩展能够成功地做到这一点。我想在androidwebview中使用java/kotlin和javascript实现相同的功能。下面是在chrome扩展中实现这一点的参考。通过chrome扩展将文件作为表单数据上传。
这里是depop表单的html输入部分。
<div data-testid="imageInputWrapper" class="ImageInputstyles__Wrapper-sc-2l692w-11 ilMHzo">
<label class="ImageInputstyles__Label-sc-2l692w-0 qRxlC">
<div>
<svg xmlns="http://www.w3.org/2000/svg" width="29" height="23" viewBox="0 0 29 23" class="ImageInputstyles__Camera-sc-2l692w-3 bdakae">
<title>Upload an image</title>
<g fill="none" fill-rule="evenodd">
<path stroke="#999" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7.2 7.082v14h20v-14h-5.968L20.2 4.5h-6l-1.14 2.582z"></path>
<path stroke="#999" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.2 16.5a3 3 0 100-6 3 3 0 000 6z"></path>
<circle cx="6.65" cy="6.65" r="6.65" fill="#FFF"></circle>
<circle cx="6.7" cy="6.6" r="5.5" fill="#FF2300"></circle>
<path stroke="#FFF" stroke-linecap="square" d="M6.7 3.6v6m-3-3h6"></path>
</g>
</svg>
<p class="ImageInputstyles__HelpText-sc-2l692w-6 iGmhpY">Add a photo</p>
</div>
<input aria-describedby="error__images" aria-label="Upload an image" tabindex="0" type="file" multiple="" accept="image/jpeg, image/png" data-testid="imageInput" class="ImageInputstyles__Input-sc-2l692w-7 aosWu">
</label>
</div>
在android中,我试图触发 onShowFileChooser
然后手动传递文件,而不实际打开文件选择器。
val script = "javascript:document.getElementsByClassName('ImageInputstyles__Label-sc-2l692w-0 qRxl')[0].click()"
depop_webview.evaluateJavascript(script
) { value -> Log.d(TAG, "onReceiveValue: $value") }
depop_webview.webChromeClient = object : WebChromeClient(){
override fun onShowFileChooser(webView: WebView?, filePathCallback: ValueCallback<Array<Uri>>?, fileChooserParams: FileChooserParams?): Boolean {
return super.onShowFileChooser(webView, filePathCallback, fileChooserParams)
}
}
但我得到一个错误 chromium: [INFO:CONSOLE(1)] "File chooser dialog can only be shown with a user activation."
. 那么,有什么方法可以将图片从url或本地存储上传到 input
字段编程?
暂无答案!
目前还没有任何答案,快来回答吧!