driver.get("url"); #個人推薦這種方式,因為能少寫一個字元是一個字元啊。
driver.navigate().to("url");
頁面的title主要用于case的驗證,當然了也有一位大神教育我說case不夠title來湊,這個作用顯著啊!
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(); //擷取目前頁面的title
string currenturl = driver.getcurrenturl(); // 擷取目前頁面的url
system.out.printf("current page's title is: %s , current url is: %s \n",title,currenturl);
try {
thread.sleep(5000);
} catch (interruptedexception e) {
e.printstacktrace();
}
driver.quit(); //徹底退出webdriver
最新内容請見作者的github頁:http://qaseven.github.io/