前の例を通じて学習、あなたは、マウスのクリック操作をシミュレートするため)(クリックを使用することができ、今のWeb製品は、マウスの右クリック、ダブルクリック、ホバー、あるいはマウスのドラッグ機能として、より豊かなマウス操作を提供します。webdriverを、これらの方法でマウスがActionChainsクラスの包装作業を提供します。
アクションクラスは、マウスの操作の一般的な方法を提供します。
- contextClick()を右クリック
- clickAndHold()マウスクリックと制御
- DoubleClickは()をダブルクリックします
- dragAndDrop()ドラッグ
- リリース()マウスを離し
- 実行()は、すべての記憶された動作アクションを実行します
Baiduのホーム設定は、ドロップダウンメニューを置きます。
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class MouseDemo {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
driver.get("https://www.baidu.com/");
WebElement search_setting = driver.findElement(By.linkText("设置"));
Actions action = new Actions(driver);
action.clickAndHold(search_setting).perform();
driver.quit();
}
}
- 輸入org.openqa.selenium.interactions.Actions。
マウスのクラスを導入することActionChainsを提供します
- アクション(ドライバ)は、パラメータとしてアクション()クラス、ブラウザのドライバドライバを呼び出します。
- マウスホバリング動作をシミュレートするために使用clickAndHold()メソッドは、呼び出しで配置要素を指定する必要があります。
- ()格納されたすべての行為のActionChainsを実行する実行、全体の動作の動作に提出されるものと理解されるであろう。
マウスでの操作1.他の方法
import org.openqa.selenium.interactions.Actions;
……
Actions action = new Actions(driver);
// 鼠标右键点击指定的元素
action.contextClick(driver.findElement(By.id("element"))).perform();
// 鼠标右键点击指定的元素
action.doubleClick(driver.findElement(By.id("element"))).perform();
// 鼠标拖拽动作, 将 source 元素拖放到 target 元素的位置。
WebElement source = driver.findElement(By.name("element"));
WebElement target = driver.findElement(By.name("element"));
action.dragAndDrop(source,target).perform();
// 释放鼠标
action.release().perform();