gpt4 book ai didi

java - 使用 WebDriver 扩展在网格上上传文件

转载 作者:行者123 更新时间:2023-12-02 11:21:06 26 4
gpt4 key购买 nike

您好,我尝试使用 Selenium 的 WebDriver 扩展,但是,在尝试上传文件时我变得不卡住。在本地,通过使用机器人上传文件,例如:robot.keyPress(KeyEvent.VK_ENTER);

但是在网格上,机器人没有按预期工作。如何使用 Selenium 和 WebDriver 扩展将文件上传到 web 应用程序?

最佳答案

我希望您正在尝试将文件从本地计算机上传到应用程序?您触发的机器人命令将应用于运行脚本的计算机(正在执行 java 的计算机),它们不会传递到节点计算机。

From Documentation: All you need to do is use the sendKeys command to type the local path of the file in any file field. This works like a charm in all drivers. When moving this test to a remote server (such as, for example, our Selenium 2 Cloud), all you need to do is use the setFileDetector method to let WebDriver know that you're uploading files from your local computer to a remote server instead of just typing a path. Almost magically, the file will be base64 encoded and sent transparently through the JSONWireProtocol for you before writing the fixed remote path.

driver.setFileDetector(new LocalFileDetector());
...
WebElement upload = driver.findElement(By.id("fileupload"));
upload.sendKeys("/path/to/file.jpg");
driver.findElement(By.id("upload")).click();

See the tutorial

关于java - 使用 WebDriver 扩展在网格上上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49916124/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com