【问题标题】:Unable to upload file by after upload window pop-up JAVA上传后弹出JAVA窗口无法上传文件
【发布时间】:2016-05-31 18:01:48
【问题描述】:

我在 Stackoverflow 上看到了很多关于使用 selenium webdriver 上传文件的问题和解决方案。但是对于以下情况都不起作用。事实上,上传窗口弹出挂在那里没有做任何事情。请指教

这是我的代码:

WebDriverWait wait = new WebDriverWait(driver, 100);
            //Upload Doc #1 
            wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='lottery']/div[3]/div[2]/input[1]"))).click();
            //Upload Doc #2 
            wait.until(ExpectedConditions.elementToBeClickable(By.id("filePicker"))).click();
            //Upload Doc #3 
            WebElement fileInput = driver.findElement(By.id("filePicker"));
            fileInput.sendKeys("D:\\SobetAuto\\5star.txt");

【问题讨论】:

  • 文件选择器让用户可以插入文件,但如果你想自动化它,你不需要打开它,只需为输入提供正确的文件值。
  • 嗨尼尔,你介意告诉我怎么做吗?谢谢
  • 我对 selenium 不熟悉,只是基于我从 phantomJS 之类的知识。你不能依赖任何需要用户交互的东西。但是,您可以代表用户预先选择文件。

标签: java selenium automation


【解决方案1】:

试试这个,看看它是否有效:

driver.findElement(By.id("filePicker")).sendKeys("D:/SobetAuto/5star.txt");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多