53

Selenium WebDriverjavaでドラッグアンドドロップ機能を自動化するには?

4

13 に答える 13

55

Advanced User Interactions を文書化したページがあります。これには、一連のアクションを生成する方法に関する多くの優れた例があり ます。ここで見つけることができます

// Configure the action
Actions builder = new Actions(driver);

builder.keyDown(Keys.CONTROL)
   .click(someElement)
   .click(someOtherElement)
   .keyUp(Keys.CONTROL);

// Then get the action:
Action selectMultiple = builder.build();

// And execute it:
selectMultiple.perform();   

また

Actions builder = new Actions(driver);

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

dragAndDrop.perform();
于 2013-01-08T19:32:36.427 に答える
37

Selenium にはかなり優れたドキュメントがあります。これは、探している API の特定の部分へのリンクです。

WebElement element = driver.findElement(By.name("source")); 

WebElement target = driver.findElement(By.name("target"));

(new Actions(driver)).dragAndDrop(element, target).perform();
于 2013-01-08T07:35:37.823 に答える
3

ドラッグアンドドロップはこのように実装できます...

public ObjectPage filter(int lowerThreshold, int highThreshold) {
    Actions action = new Actions(getWebDriver());
    action.dragAndDropBy(findElement(".className .thumbMin"), lowerThreshold, 0).perform();
    waitFor(elementIsNotDisplayed("#waiting_dialog"));

    action.dragAndDropBy(findElement(".className .thumbMax"), highThreshold, 0).perform();
    waitFor(elementIsNotDisplayed("#waiting_dialog"));
    return this;
}

それが役立つことを願っています!

于 2015-06-18T07:16:02.173 に答える
3

Selenium には、ドラッグ アンド ドロップを実行するための非常に多くのオプションがあります。

Action クラスには、同じタスクを実行するメソッドがいくつかあります。

考えられる解決策をリストアップしましたので、ご覧ください。

http://learn-automation.com/drag-and-drop-in-selenium-webdriver-using-actions-class/

于 2015-10-31T19:20:39.937 に答える
3

これを試してください:

    Actions builder = new Actions(fDriver);
    builder.keyDown(Keys.CONTROL)
        .click(element)
        .dragAndDrop(element, elementDropped)
        .keyUp(Keys.CONTROL);

        Action selected = builder.build();

        selected.perform();
于 2016-01-11T11:38:10.353 に答える
1

もう1つの方法は、draganddrop()このように使用することです

      WebElement element = driver.findElement(By.name("source"));
      WebElement target = driver.findElement(By.name("target"));

     (new Actions(driver)).dragAndDrop(element, target).perform();
于 2014-02-27T05:16:38.557 に答える
1

Selenium::Remote::Driver を使用して、Perl でこのようにします。

my $sel = <>;  #selenium handle
my $from_loc = <fromloc>;
my $to_loc   = <toloc>;

my $from_element = $sel->find_element($from_loc);
my $to_element = $sel->find_element($to_loc);

# Move mouse to from element, drag and drop
$sel->mouse_move_to_location(element=>$from_element);
$sel->button_down(); # Holds the mouse button on the element
$sel->mouse_move_to_location(element=>$to); # Move mouse to the destination
$sel->button_up();

これでできるはずです!

于 2015-02-11T03:23:40.410 に答える
1
    WebElement fromElement= driver.findElement(By.xpath("SourceElement"));
    WebElement toElement=driver.findElement(By.xpath("TragetElement"));
    Actions action = new Actions(WebDriver);
    Action dragDrop = action.dragAndDrop(fromElement, toElement).build();
    dragDrop.perform(); 
于 2014-12-05T11:51:26.933 に答える
0

Selenium にはかなり優れたドキュメントがあります。探している API の特定の部分へのリンクを次に示します。

WebElement element = driver.findElement(By.name("source"));

WebElement target = driver.findElement(By.name("target"));

(new Actions(driver)).dragAndDrop(element, target).perform();

これは単一のファイルをドラッグ アンド ドロップする方法で、複数のファイルをドラッグ アンド ドロップする方法です。

于 2016-07-19T09:54:57.477 に答える