Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.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 当我尝试使用Jquery上传文件时,它会抛出错误_Java_Jquery_Selenium_Automation - Fatal编程技术网

Java 当我尝试使用Jquery上传文件时,它会抛出错误

Java 当我尝试使用Jquery上传文件时,它会抛出错误,java,jquery,selenium,automation,Java,Jquery,Selenium,Automation,我的代码引发以下错误: org.openqa.selenium.elementNotInteractitableException:元素不可交互:未能在“HTMLInputElement”上设置“value”属性:此输入元素接受文件名,该文件名只能以编程方式设置为空字符串。 (会话信息:chrome=89.0.4389.114) 公共支出请求页面点击删除(){ JavascriptExecutor jse=(JavascriptExecutor)驱动程序; URL jqueryUrl=Resou

我的代码引发以下错误:

org.openqa.selenium.elementNotInteractitableException:元素不可交互:未能在“HTMLInputElement”上设置“value”属性:此输入元素接受文件名,该文件名只能以编程方式设置为空字符串。 (会话信息:chrome=89.0.4389.114)

公共支出请求页面点击删除(){
JavascriptExecutor jse=(JavascriptExecutor)驱动程序;
URL jqueryUrl=Resources.getResource(“jquery-1.8.2.min.js”);
字符串jqueryText=null;
试一试{
jqueryText=Resources.toString(jqueryUrl,Charsets.UTF_8);
}捕获(IOE异常){
e、 printStackTrace();
}
jse.executeScript(jqueryText);
jse.executeScript(“$(\”输入[id$='fafa']\”)。单击();
jse.executeScript($(\“input[id$='fafa']\”).val(\“C:\\Users\\Gayathri\\Documents\\EBPAutomation\\WBPTest\\src\\test\\resources\\FERPA.docx\”);
归还这个;
}

当您尝试使用Selenium将文件从计算机上载到站点时,您不会使用JavaScript注入。在应该将文件上载到站点的元素上使用element.sendKeys

 WebDriverWait wait = new WebDriverWait(browser, 10);
 WebElement elementToFind = wait.until(ExpectedConditions.
 presenceOfElementLocated(By.id(elementId)));
 elementToFind.sendKeys(keys);

在上面的示例中,keys参数应该保留文件的路径。

错误非常明显。您正在尝试设置
input type=“file”
元素的值,但由于明显的安全原因,这是不可能的。请注意,这与按标题所示上传文件无关。有什么解决方案吗?另外,请注意,jquery 1.8.2非常过时,存在安全问题。在编写本书时,您应该考虑将其升级到最新版本3.6.0。如果可能的话,这将是一个巨大的安全漏洞。感谢您的输入:)