get() 方法和 navigate() 方法之間的差異是什麼?
get() 和 navigate() 方法之間的差異如下所示。
| sl.no. | get() | navigate() |
|---|---|---|
| 1 | 它負責載入頁面並等待頁面完成載入。 | 它只負責重定向頁面,然後立即返回。 |
| 2 | 它無法跟蹤瀏覽器的歷史記錄。 | 它跟蹤瀏覽器歷史記錄,可以在瀏覽器中執行後退和前進操作。 |
示例
使用 get().
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
import java.util.List;
public class LaunchBrw {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String url = "https://tutorialspoint.tw/index.htm";
driver.get(url);
driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
driver.close();
}
}示例
使用 navigate().
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
import java.util.List;
public class BrowserNavigation {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String url = "https://tutorialspoint.tw/index.htm";
// new browser will launch and navigate to the URL
driver.navigate().to(url);
driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
// refresh the current browser
driver.navigate().refresh();
//Using id tagname attribute combination for css expression
driver.findElement(By.cssSelector("input[name=’search’]")). sendKeys("Selenium");
//browser will go back to the previous page
driver.navigate().back();
//browser will go move to the next page
driver.navigate().forward();
driver.close();
}
}
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP