【发布时间】:2017-09-08 10:27:17
【问题描述】:
要在此 URL 中的字段上上传图像:http://demoqa.com/registration/ 我使用了以下适用于 chrome 但不适用于 Firefox 的代码。请问一下原因和解决方法?
WebDriver driver;
System.setProperty("webdriver.gecko.driver","C:\\Users\\abc\\Desktop\\Selenium\\geckodriver-v0.17.0-win64\\geckodriver.exe");
driver = new FirefoxDriver();
driver.get("http://demoqa.com/registration/");
WebElement elementUpload=driver.findElement(By.xpath("//*[@id='profile_pic_10']"));
WebDriverWait wait=new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(elementUpload));
elementUpload.sendKeys("D:\\roboraid.jpg");
这里显示的错误是:
Exception in thread "main" org.openqa.selenium.InvalidArgumentException: File not found: C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg
【问题讨论】:
-
xpath 不正确:ty this //*[@id='profile_pic_10'],也可能是您的文件不存在
-
我从它的属性中获取了文件路径,所以这不会是错误的
-
所以是文件放置的问题,你在错误日志中找不到错误文件,可以给你我输出的快照
-
是的,你可以
-
还将文件夹名称改为samplespace
标签: java selenium-webdriver selenium-firefoxdriver