Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法通过上载后窗口弹出的JAVA上载文件_Java_Selenium_Automation - Fatal编程技术网

无法通过上载后窗口弹出的JAVA上载文件

无法通过上载后窗口弹出的JAVA上载文件,java,selenium,automation,Java,Selenium,Automation,在Stackoverflow上使用SeleniumWebDriver上传文件时,我看到了很多问题和解决方案。但这些都不适用于以下场景。实际上,上传窗口弹出窗口挂在那里,什么也不做。恳请告知 这是我的代码: WebDriverWait wait = new WebDriverWait(driver, 100); //Upload Doc #1 wait.until(ExpectedConditions.elementToBeClickable(By

在Stackoverflow上使用SeleniumWebDriver上传文件时,我看到了很多问题和解决方案。但这些都不适用于以下场景。实际上,上传窗口弹出窗口挂在那里,什么也不做。恳请告知

这是我的代码:

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");

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

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

文件选择器允许用户插入文件,但如果您试图自动执行,则无需打开它,只需为输入提供正确的文件值。嗨,尼尔,您介意告诉我如何操作吗?谢谢,我对硒并不熟悉,只是根据我从幻影之类的东西了解的。你不能依赖任何需要用户交互的东西。但是,您可以代表用户预先选择文件。