Selenium NoSuchElementException:无法使用RemoteWebDriver Java找到使用By.xpath的元素
在本地计算机上运行拖放文件上载脚本工作正常,测试通过,但尝试远程运行同一脚本-RemoteWebDriver时,测试失败,出现异常:Selenium NoSuchElementException:无法使用RemoteWebDriver Java找到使用By.xpath的元素,java,selenium,selenium-webdriver,selenium-grid,remotewebdriver,Java,Selenium,Selenium Webdriver,Selenium Grid,Remotewebdriver,在本地计算机上运行拖放文件上载脚本工作正常,测试通过,但尝试远程运行同一脚本-RemoteWebDriver时,测试失败,出现异常: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@class='dz-message']"
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element:
{"method":"xpath","selector":"//*[@class='dz-message']"}
(Session info: chrome=62.0.3202.75)
(Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT
6.3.9600 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 50 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
System info: host: 'vc2coma1395994', ip: '10.146.2.48', os.name: 'Windows Server 2012 R2', os.arch:
'amd64', os.version: '6.3', java.version: '1.8.0_211'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false,
我尝试过使用显式等待,但没有任何效果
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@class='dz message']")));
这是密码
驱动程序。获取(“http://html5demos.com/file-api");
WebElement droparea=driver.findElement(By.cssSelector(“#holder”)
@FindBy(how = How.XPATH, using = "//*[@class='dz-message']")
private WebElement target;
public void dropFile(String filePath){
File file = new File(filePath);
int offsetX =0, offsetY=0;
if(!file.exists())
throw new WebDriverException("File not found: " +
file.toString());
JavascriptExecutor jse = (JavascriptExecutor)driver;
WebDriverWait wait = new WebDriverWait(driver, 30);
String JS_DROP_FILE =
"var target = arguments[0]," +
" offsetX = arguments[1]," +
" offsetY = arguments[2]," +
" document = target.ownerDocument || document," +
" window = document.defaultView || window;" +
"" +
"var input = document.createElement('INPUT');" +
"input.type = 'file';" +
"input.style.display = 'none';" +
"input.onchange = function () {" +
" var rect = target.getBoundingClientRect()," +
" x = rect.left + (offsetX || (rect.width >> 1))," +
" y = rect.top + (offsetY || (rect.height >> 1))," +
" dataTransfer = { files: this.files };" +
"" +
" ['dragenter', 'dragover', 'drop'].forEach(function (name) {" +
" var evt = document.createEvent('MouseEvent');" +
" evt.initMouseEvent(name, !0, !0, window, 0, 0, 0, x, y, !1, !1, !1, !1, 0,
null);" +
" evt.dataTransfer = dataTransfer;" +
" target.dispatchEvent(evt);" +
" });" +
"" +
" setTimeout(function () { document.body.removeChild(input); }, 25);" +
"};" +
"document.body.appendChild(input);" +
"return input;";
WebElement input = (WebElement)jse.executeScript(JS_DROP_FILE, target, offsetX, offsetY);
input.sendKeys(file.getAbsoluteFile().toString());
wait.until(ExpectedConditions.stalenessOf(input));
}