Java如何打开Chrome浏览器呢?
下文笔者讲述java代码打开Chrome浏览器的方法分享,如下所示
Java打开Chrome浏览器的实现思路
借助WebDriver驱动(ChromeDriver),即可打开Chrome浏览器例:打开Chrome浏览器,并访问指定网页
package com.java265; import java.io.File; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class TestOpenBrowser { public static void main(String[] args) { //设置启动google浏览器的驱动和位置 System.setProperty("webdriver.chrome.driver", "C:"+File.separator+ "Program Files (x86)"+File.separator+ "Google"+File.separator+ "Chrome"+File.separator+ "Application"+File.separator+ "chromedriver.exe"); System.out.println("启动 ..."); //获取谷歌浏览器驱动 WebDriver driver=new ChromeDriver(); //设置默认打开的页面 driver.get("https://www.java265.com/"); //设置默认搜索的关键字 driver.findElement(By.id("kw")).sendKeys("eclipse窗口集成浏览器"); //搜索按钮点击 driver.findElement(By.id("su")).click(); //关闭浏览器 // driver.close(); } }
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。