如何处理从模态窗口Selenium WebDriver Java上传文件 [英] How to handle with uploading files from modal window Selenium WebDriver Java

查看:148
本文介绍了如何处理从模态窗口Selenium WebDriver Java上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要上传文件。
步骤是:
1.点击按钮哪个cal模态窗口。 (Linux窗口没有位置栏)
2.选择正确的文件并上传。

I need to upload file. Steps are: 1. Clicking on on button which cal modal Window. (Linux window has no location bar) 2. To choose right file and upload it.

非常感谢任何帮助。
使用Chrome Firefox驱动程序和Java。

Very appreciate any help. Using Chrome Firefox drivers and Java.

推荐答案

这已被要求多次,也在一些Selenium FAQ中。

This has been asked several times and is also in some Selenium FAQ.

// assuming driver is a well instantiated WebDriver
WebElement fileInput = driver.findElement(By.xpath("//input[@type='file']"));
fileInput.sendKeys("C:/path/to/file.jpg");

我们的想法是直接将文件的路径发送到您经常点击的元素获取模态窗口 - 即< input type ='file'/> 元素。

The idea is to directly send the path to the file to an element which you would usually click at to get the modal window - that is <input type='file' /> element.

这篇关于如何处理从模态窗口Selenium WebDriver Java上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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