JAVA操作selenium的简单示例

什么是selenium

一套软件工具,用来支持不同的自动化测试方法

开源软件:可以根据需要来增加重构工具的某些功能

跨平台:linux , windows, mac

核心功能就是可以在多个浏览器上进行自动化测试(Chrom,Opera,Windows phone,Firefox等

支持多种编程语言

目前已经被google , 百度, 腾讯等公司广泛使用

能够实现类似商业工具的大部分功能,并且还实现了商业工具不能支持的功能

代码演示:

	public static void test() throws InterruptedException{
		System.setProperty("webdriver.firefox.marionette", "C:\\Program Files (x86)\\Mozilla Firefox\\geckodriver.exe"); 
		WebDriver driver = new FirefoxDriver();
		//实现窗口最大化
		driver.manage().window().maximize();
		//打开百度首页
		driver.get("https://www.baidu.com");
		//通过ID,找到文本输入框
		WebElement shurukuang = driver.findElement(By.id("kw"));
		//设置输入框的内容
		shurukuang.sendKeys("战狼2");
		//通过ID,找到搜索按钮
		WebElement tijiao = driver.findElement(By.id("su"));
		//点击搜索按钮
		tijiao.click();
		//关闭浏览器
		driver.close();
	}


jar包下载地址:http://docs.seleniumhq.org/download/

百度网盘下载地址:链接:http://pan.baidu.com/s/1o7AlLYM 密码:ax8u

驱动下载地址:https://github.com/mozilla/geckodriver/releases/tag/v0.9.0

驱动百度网盘地址:链接:http://pan.baidu.com/s/1pLDhR6r 密码:pmjh

注意:

1:如果你用的jar包是3点几的,一定要下载驱动,驱动地址在已经提供了。否则会报错这个错

The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值