【发布时间】:2018-05-24 01:13:24
【问题描述】:
上传照片按钮在 Selenium Webdriver 中不起作用
我已经厌倦了
driver.findElement(uploadPhotoBtn).sendKeys("E:\\photo.png");
也试过Robot函数
driver.findElement(uploadPhotoBtn).click();
StringSelection ss = new StringSelection(logoPath);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
同样的Robot 功能适用于另一个上传按钮,但在尝试在这里使用时,.click 不起作用,这就是无法使用Robot 功能的原因。
HTML页面来源:
> <div ng-show="!status.uploading" ng-class="{ '!isMobile':
> 'mewe-type-1' }" class="uploader-able !isMobile"><!-- ngIf: isMobile
> --><!-- ngIf: !isMobile --><button ng-if="!isMobile" class="btn-action radius ng-scope">Upload Photo</button><!-- end ngIf: !isMobile
> --><input capture="camera" accept="image/*" name="image" type="file" fileread="fileread" file="file" class="ng-isolate-scope"></div>
控制台日志:
org.openqa.selenium.WebDriverException: 未知错误: Element ... is 在点 (314, 477) 不可点击。其他元素将收到 点击: (会话信息:chrome=66.0.3359.181)(驱动程序信息: chromedriver=2.35.528161
【问题讨论】:
-
试试
driver.findElement(By.name("image")).sendKeys("<path/to/the/file>") -
谢谢,我已经试过了 :),但是不行...
-
在发布此问题之前,我已经尝试过此解决方案。机器人解决方案从那里应对。
-
@AlImran :当您手动单击按钮时,您是否必须向下滚动或执行任何操作?
标签: java selenium selenium-webdriver selenium-chromedriver