webdriver知識點總結

基礎知識: http://www.360doc.com/content/12/0525/16/1073512_213657192.shtml

源碼下載:https://code.google.com/p/selenium/downloads/detail?name=selenium-java-2.35.0.zip


切換到當前窗口:

	public static void switchToCurrentWindow(WebDriver driver){
	    //get current window
	    String currentWindow = driver.getWindowHandle();  
	    //get all windows
	    Set<String> handles = driver.getWindowHandles();  
	    Iterator<String> it = handles.iterator();  
	    while(it.hasNext()){  
	        String handle = it.next();  
	        if(currentWindow.equals(handle)) continue;  
	        WebDriver window = driver.switchTo().window(handle);  
	        System.out.println("windows changed,the title and url is "+window.getTitle()+","+window.getCurrentUrl());  
	    }
	}

移動鼠標:

	public static void mouseToElement(WebDriver driver,String elementId){
	    Actions action = new Actions(driver);
	    action.moveToElement(driver.findElement(By.id(elementId))).build().perform();
	}


發佈了37 篇原創文章 · 獲贊 4 · 訪問量 13萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章