Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何执行拖放操作;在SeleniumWebDriver中,我们需要将文件从本地计算机拖动到web门户中的Drop功能?_Selenium_Selenium Webdriver - Fatal编程技术网

如何执行拖放操作;在SeleniumWebDriver中,我们需要将文件从本地计算机拖动到web门户中的Drop功能?

如何执行拖放操作;在SeleniumWebDriver中,我们需要将文件从本地计算机拖动到web门户中的Drop功能?,selenium,selenium-webdriver,Selenium,Selenium Webdriver,如何在Selenium WebDriver中执行拖放功能 我们需要将文件从本地计算机拖动到web门户 我正在寻找一种方法,通过这种方法,我们可以将文件直接拖放到网页上 我的一个朋友刚刚告诉我,我们不能这样做,但我们可以使用Robot()class在网页中这样做。代码如下: package com; import java.awt.Robot; import java.awt.event.InputEvent; import org.openqa.selenium.WebDriver; im

如何在Selenium WebDriver中执行拖放功能 我们需要将文件从本地计算机拖动到web门户


我正在寻找一种方法,通过这种方法,我们可以将文件直接拖放到网页上

我的一个朋友刚刚告诉我,我们不能这样做,但我们可以使用
Robot()
class在网页中这样做。代码如下:

package com;
import java.awt.Robot; 
import java.awt.event.InputEvent; 

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test; 

public class Robott { 

    @Test 
    public void DragnDrop() throws Exception { 
        WebDriver driver = new FirefoxDriver(); 
        driver.get("http://gmail.com"); 
        Robot r = new Robot(); 
        Thread.sleep(4000); 
        r.mouseMove(400, 350); 
        r.mousePress(InputEvent.BUTTON1_MASK); 
        Thread.sleep(2000); 
        r.mouseMove(500, 350); 
        r.mouseRelease(InputEvent.BUTTON1_MASK); 
    } 
}

通过使用
Robot()
类,我们可以执行鼠标和键盘操作,因此它可能在这里工作。

您可以尝试Selenium高级交互方法

例如:

Actions builder = new Actions(driver);

Action dragAndDrop = builder.clickAndHold(someElement)
    .moveToElement(otherElement)
    .release(otherElement)
    .build();

dragAndDrop.perform();

有关详细信息,请检查

门户网站是否有输入文件名的界面?提供URL,我可能会告诉你如何。它可能适用于特定的机器。但如果屏幕分辨率不同,测试就会失败。除此之外,实际上这是一次很好的尝试