嗨,你能帮我上传一个文件在Safari,Mac。
我给出了一个网站,我们可以通过点击“选择文件”按钮(JPG,PNG,GIF,DOC,XLS,PDF,ZIP,RAR,ZIPX)上传以下类型的文件
package Default;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.safari.SafariDriver;
public class Safari_demo {
public static void main(String[] args) throws InterruptedException{
WebDriver driver = new SafariDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Thread.sleep(6000);
driver.get("http://www.files.com/");
driver.findElement(By.id("uploadFields")).click();
//can you please help me with code in this line
//this is the place were i need to enter the address of the
//file which is in my system
driver.close();
}
}发布于 2015-08-25 12:05:21
SafariDriver似乎不支持文件上传:https://code.google.com/p/selenium/issues/detail?id=4220
发布于 2015-04-07 10:25:13
尝尝这个。
fd.findElement(By.xpath(".//*[@id='uploadFields']/input"))
.sendKeys(
"your image path");发布于 2015-04-07 09:20:20
因此,文件上传对话框实际上是一个本地系统对话框,而不是web对话框,因此您不能使用Selenium与其交互。在本地这样做的方法是将路径发送到filePath文本框,茶碟很好地描述了它:
对于在本地执行此操作的人,只需使用sendKeys命令在任何文件字段中键入文件的本地路径。这对所有司机来说都是一种魅力。当将此测试移动到远程服务器(例如,我们的Selenium2Cloud)时,您所需要做的就是使用setFileDetector方法让WebDriver知道,您正在将文件从本地计算机上载到远程服务器,而不仅仅是键入路径。几乎神奇的是,在编写固定的远程路径之前,文件将被base64编码并透明地通过JSON发送。这是一个很好的解决方案,因为它允许您将测试从本地切换到远程驱动程序,而不必担心更改测试代码。
https://stackoverflow.com/questions/29483701
复制相似问题