如何通过 java 和 selenium "Grid" 的远程 StringSelection?

How past the StringSelection in remote with java and selenium "Grid"?

我尝试使用机器人 class 和 selenium 网格上传文件。

我可以在本地执行此操作 windows 但是当我尝试在远程计算机中上传时,我无法在远程计算机中通过 StringSelection,StringSelection 在本地已通过。

这是我的代码。

public static void adjFile1() throws AWTException {
        Robot rbt = new Robot();

        StringSelection path = new StringSelection(
                "C:\Users\tpereira\eclipse_git\BCN_WorkFlow_1\src\test\resources\Archivos\Contrato 2 FCB.pdf");

        // create an object to desktop
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(path, null);

        rbt.delay(2000);
        // copy the path into mouse
        rbt.keyPress(KeyEvent.VK_ENTER);
        rbt.keyRelease(KeyEvent.VK_ENTER);
        rbt.keyPress(KeyEvent.VK_CONTROL);
        rbt.keyPress(KeyEvent.VK_V);
        rbt.keyRelease(KeyEvent.VK_V);
        rbt.keyRelease(KeyEvent.VK_CONTROL);
        rbt.keyPress(KeyEvent.VK_ENTER);
        rbt.keyRelease(KeyEvent.VK_ENTER);

@Then("^I attach the process documentation \"([^\"]*)\"$")
    public void adjuntoDocumentacionDelProceso(String expectedMessage) throws Throwable {

        JavascriptExecutor jse = (JavascriptExecutor) driver;
        rbt = new Robot();
        WebDriverWait wait = new WebDriverWait(driver, 10);
        WebElement upLoad = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(adj_Doc)));
        jse.executeScript("arguments[0].scrollIntoView();", upLoad);
        upLoad.click();

        Functions_w_1.adjFile1();

        rbt.delay(1000);
        String message = driver.findElement(By.xpath(popUp_Error_Solic)).getText();
        System.out.println("Documento adjuntado correctamente: " + message.toString());
        Assert.assertTrue("No se ha adjuntado el archivo!!!", message.contains(expectedMessage));

    }

我可以使用此代码在虚拟机中使用 Selenium Grid 远程附加文件。 现在我只需要关闭点击打开的window。

    public void adjuntoDocumentacionDelProceso(String expectedMessage) throws Throwable {

        JavascriptExecutor jse = (JavascriptExecutor) driver;
        rbt = new Robot();
        WebDriverWait wait = new WebDriverWait(driver, 10);
        WebElement upLoad = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(adj_Doc)));
        jse.executeScript("arguments[0].scrollIntoView();", upLoad);
        upLoad.click();
        rbt.delay(800);

        driver.switchTo().activeElement().sendKeys("C:\Users\QABCN\Documents\contractos\Contrato 1 FCB.pdf");
        //functionsEspai.adjFile1();

        rbt.delay(1000);
        String message = driver.findElement(By.xpath(popUp_Error_Solic)).getText();
        Assert.assertTrue("No se ha adjuntado el archivo!!!", message.contains(expectedMessage));

        System.out.println("Documento adjuntado correctamente: " + message.toString());

    }```