我正在尝试自动化Blueimp文件上传。但不断获得ElementNotVisible
例外。
WebElement fileUpload = driver.findElement(By.xpath("//input[@type='file']"));
String imagePath = "image.png";
fileUpload.sendKeys(imagePath);
我尝试启用:
((JavascriptExecutor)driver).executeScript("arguments[0].checked = true;", fileUpload);`
但仍然没有运气..
答案 0 :(得分:1)
解决问题的一个方法是使元素可见:
WebElement fileUpload = driver.findElement(By.xpath("//input[@type='file']"));
((JavascriptExecutor)driver).executeScript("arguments[0].style.display = 'block'; arguments[0].style.visibility = 'visible';", fileUpload);
String imagePath = "image.png";
fileUpload.sendKeys(imagePath);
另见: