利用webDriver進行自動化的筆記

1.取得控件上的值:element.getText();

   取得輸入框中的值:element.getAttribute("value");

2.在指定位置點擊鼠標右鍵:

   Actions actions = new Actions(driver);

   actions.contextClick(driver.findElement(By.xpath(targetXpath)));

   actions.perform();

3.移動鼠標到指定位置,然後進行點擊:

   Actions builder = new Actions(driver);
   Action action=builder.moveToElement(element).build();
   action.perform();

   element.click();

   如果要點擊這個元素下的其他元素:

   String xpath = "要點擊元素的xpath";

   WebElement element = driver.findElement(By.xpath(xpath));

   element.click();

4.要使用ChromeDriver,得先下載chromedriver.exe放進工程中,然後將其加入到系統屬性中。

   System.setProperty("webdriver.chrome.driver", Utils.getPath(Constants.chromeDriverFolder, "chromedriver.exe"));

   WebDriver driver = new ChromeDriver();

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章