多测师是一家拥有先进的教学理念,强大的师资团队,业内好评甚多的接口自动化测试培训机构!

17727591462

联系电话

您现在所在位置:接口自动化测试培训 > 新闻资讯

Selenium打开Google浏览器的简单实例-自动化测试

更新时间:2022-03-31 09:37:29 作者:多测师 浏览:203

  首先在eclipse中引入selenium的包,本实例用的是selenium-server-standalone-3.10.0,chromedriver2.35,以及chrome浏览器64.0.3282.186。注意chromedriver与chrome之间的版本匹配关系。

Selenium打开Google浏览器的简单实例-自动化测试

  package com.datashow.util;

  import org.openqa.selenium.By;

  import org.openqa.selenium.WebDriver;

  import org.openqa.selenium.WebElement;

  import org.openqa.selenium.chrome.ChromeDriver;

  public class DataCatch {

  public static void main(String[] args) {

  System.out.println("即将打开谷歌浏览器进行探索...");

  System.setProperty("webdriver.chrome.driver", "D:\\Program_Files\\Chrome\\chromedriver.exe");//指定驱动路径

  WebDriver driver = new ChromeDriver();

  driver.get("http://www.baidu.com/");

  String oo = driver.getCurrentUrl();

  System.out.println(oo);

  WebElement keywords= driver.findElement(By.name("wd"));

  keywords.sendKeys("积德从善");

  WebElement keysubmit=driver.findElement(By.id("su"));

  keysubmit.click();

  System.out.println("已经成功打开谷歌浏览器...");

  }

  }

  以上内容为大家介绍了自动化测试中的Selenium打开Google浏览器的简单实例,本文由多测师亲自撰写,希望对大家有所帮助。了解更多自动化测试相关知识:https://www.aichudan.com/xwzx/

联系电话

17727591462

返回顶部