Selenium WebDriver
javaでドラッグアンドドロップ機能を自動化するには?
13 に答える
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();
Selenium にはかなり優れたドキュメントがあります。これは、探している API の特定の部分へのリンクです。
WebElement element = driver.findElement(By.name("source"));
WebElement target = driver.findElement(By.name("target"));
(new Actions(driver)).dragAndDrop(element, target).perform();
ドラッグアンドドロップはこのように実装できます...
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;
}
それが役立つことを願っています!
Selenium には、ドラッグ アンド ドロップを実行するための非常に多くのオプションがあります。
Action クラスには、同じタスクを実行するメソッドがいくつかあります。
考えられる解決策をリストアップしましたので、ご覧ください。
http://learn-automation.com/drag-and-drop-in-selenium-webdriver-using-actions-class/
これを試してください:
Actions builder = new Actions(fDriver);
builder.keyDown(Keys.CONTROL)
.click(element)
.dragAndDrop(element, elementDropped)
.keyUp(Keys.CONTROL);
Action selected = builder.build();
selected.perform();
もう1つの方法は、draganddrop()
このように使用することです
WebElement element = driver.findElement(By.name("source"));
WebElement target = driver.findElement(By.name("target"));
(new Actions(driver)).dragAndDrop(element, target).perform();
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();
これでできるはずです!
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();
Selenium にはかなり優れたドキュメントがあります。探している API の特定の部分へのリンクを次に示します。
WebElement element = driver.findElement(By.name("source"));
WebElement target = driver.findElement(By.name("target"));
(new Actions(driver)).dragAndDrop(element, target).perform();
これは単一のファイルをドラッグ アンド ドロップする方法で、複数のファイルをドラッグ アンド ドロップする方法です。