您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
Selenium2.0功能測試之訪問站點及獲取頁面信息
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2013/10/11 16:34:14 ] 推薦標(biāo)簽:

  Selenium為訪問站點提供了兩種方式:
  driver.get("URL");   #個人推薦這種方式,因為能少寫一個字符是一個字符啊。
  driver.navigate().to("URL");
  頁面的Title主要用于case的驗證,當(dāng)然了也有一位大神教育我說case不夠title來湊,這個作用顯著啊!
  頁面的URL也主要是用于case的驗證,URL的一個重要的測試領(lǐng)域是對于重定向的測試(很多地址當(dāng)你訪問后會自動的跳轉(zhuǎn)到其他的地址,這時URL 驗證的機(jī)會來了,當(dāng)然了還是有很多其他的地方能用到一時想不出來了這些吧!)
package org.coderinfo.demo;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class GetWebSiteAndPrintWebInfo {
private static final String URL = "http://www.google.com.hk";
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize(); //大化瀏覽器界面
driver.get(URL); // 等同于 driver.navigate().to(URL); 訪問谷哥的首頁 ,此處放棄度娘。
String title = driver.getTitle(); //獲取當(dāng)前頁面的title
String currentUrl = driver.getCurrentUrl(); // 獲取當(dāng)前頁面的URL
System.out.printf("Current page's title is: %s , Current URL is: %s ",title,currentUrl);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
driver.quit();  //徹底退出WebDriver
}
}

相關(guān)鏈接:
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd