Selenium Webdriver Java-使用phantomjs驱动程序上传文件 [英] Selenium webdriver java - upload file with phantomjs driver

查看:194
本文介绍了Selenium Webdriver Java-使用phantomjs驱动程序上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Phantomjs驱动程序无头运行Selenium Webdriver脚本.我在上传文件时遇到问题,因为在普通浏览器(firefox或chrome)上,它将弹出OS对话框,该对话框允许我在机器中找到文件并上传. 如何使用ghostDriver(Phantomjs驱动程序)来做到这一点? 谢谢

I am running a selenium webdriver script headless using Phantomjs Driver. I am having issues uploading a file though since on a normal browser (firefox or chrome) it would pop up the OS dialog box that would allow me to locate the file in my machine and upload it. How to do that with the ghostDriver (Phantomjs Driver)? Thanks

推荐答案

var webPage = require('webpage');   
var page = webPage.create();
page.uploadFile('input[name=image]', '/path/to/some/photo.jpg');

在新版本的phantomjs中,您可以像这样上传文件 上传文件

in the new version of phantomjs, you can upload file like this uploadfile

这篇关于Selenium Webdriver Java-使用phantomjs驱动程序上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆