WebElement product_image = driver.findElement(By.id("pdt_upload_preview"));
System.out.println("-------Product image selected----------\n-----------------------");
product_image.click();
product_image.sendKeys("C:\\TEST\\TEST\\Images\\Images(1).jpg");我不能用这个上传文件。
发布于 2019-10-21 16:25:17
我希望不需要点击,只需尝试
WebElement product_image = driver.findElement(By.id("pdt_upload_preview"));
product_image.sendKeys("C:\\TEST\\TEST\\Images\\Images(1).jpg");发布于 2019-10-22 00:31:21
如果你的代码不能正常工作,你的图片上传元素可能被隐藏了。您可以尝试执行Javascript来显示元素:
WebElement product_image = driver.findElement(By.id("pdt_upload_preview"));
// execute javascript to reveal the element
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].style.display = 'block';", product_image);
// send keys to the element
product_image.sendKeys("C:\\TEST\\TEST\\Images\\Images(1).jpg");https://stackoverflow.com/questions/58480790
复制相似问题