Selenium:在 Google Chrome 中上传文件 [英] Selenium: Upload file in Google Chrome

查看:57
本文介绍了Selenium:在 Google Chrome 中上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Selenium RCattach_file"仅支持*Firefox,有没有办法在Google Chrome 中上传文件?非常感谢任何建议或解决方法.

Is there any way to upload file in Google Chrome since Selenium RC "attach_file" only supports *Firefox? Any suggestion or workarounds are much appreciated.

推荐答案

如果您使用的是 Webdriver,那么上传文件您只需要使用sendKeys"来输入文件路径.您需要跳过"单击打开对话框以选择文件的浏览按钮的部分.对我有用的 Java 版本如下所示,

If you are using Webdriver then to upload file all you need is use "sendKeys" to type the file path. You need to 'skip' the part of clicking on the browse button that opens a dialog box to select the file. A Java version that works for me looks something like below,

WebElement inputFilePath = driver.findElement(By.id("filepath"));
inputFilePath.sendKeys("/absolute/path/to/my/local/file");

这篇关于Selenium:在 Google Chrome 中上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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