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.com/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.com/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