废话不多说,直接上代码,拿来就可以运行。
package com.example.Open;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.*;
public class API {
public static void main(String[] args) { System.setProperty("webdriver.chrome.driver","C:\\Users\\ihm\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe");
//((JavascriptExecutor)webdriver.chrome.driver).executeScript("alert(\"hello,this is a alert!\")");
String url = "https://www.youkuaiyun.com";
WebDriver driver = new ChromeDriver();
//用 get 方法
driver.get(url);
//用 navigate 方法,然后再调用 to 方法
driver.navigate().to(url);
System.out.println("当前页面的标题是: "+driver.