Selenium启动Firefox示例(java版)
本文示例使用selenium启动Firefox,并将浏览器窗口最大化,在百度搜索框内输入“HelloWorld”,最后点击搜索按钮。
源代码如下:
1 package com.selenium.test;
2
3 import java.util.concurrent.TimeUnit;
4 import org.openqa.selenium.By;
5 import org.openqa.selenium.WebDriver;
6 import org.openqa.selenium.WebElement;
7 import org.openqa.selenium.firefox.FirefoxDriver;
8
9 public class testGome {
10 public static void main(String[] args) {
11 //如果火狐浏览器没有默认安装在C盘,需要制定其路径
12 //System.setProperty("webdriver.firefox.bin", "D:/Program Files (x86)/Mozilla Firefox/firefox.exe");
13 System.setProperty("webdriver.firefox.marionette","C:\\Program Files (x86)\\Mozilla Firefox\\geckodriver.exe");
14 //WebDriver driver=new FirefoxDriver(); C:\Program Files (x86)\Mozilla Firefox
15 //定义驱动对象为 FirefoxDriver 对象
16 WebDriver driver = new FirefoxDriver();
17 //驱动的网址
18 driver.get("https://www.baidu.com/");
19 //浏览器窗口变大
20 driver.manage().window().maximize();
21 //定位输入框元素
22 WebElement txtbox = driver.findElement(By.name("wd"));
23 //在输入框输入文本
24 txtbox.sendKeys("HelloWorld");
25 //定位按钮元素
26 WebElement btn = driver.findElement(By.id("su"));
27 //点击按钮
28 btn.click();
29 //关闭驱动
30 driver.close();
31 }
32 }
下一篇文章介绍python版Selenium启动Firefox浏览器。
Selenium启动Firefox示例(java版)的更多相关文章
- Selenium启动Firefox示例(python版)
目前做selenium自动化使用的主流语言分为java和python,前一篇为java版,本篇介绍python实现selenium启动Firefox. 1 #-*- coding:utf-8 -*- ...
- selenium启动Firefox失败
今天搭建java+selenium环境,搭建几次都失败,总结一下原因 1. selenium启动Firefox,不需要额外的driver 2. Friefox如果没有安装到默认路径C盘,代码中需要修改 ...
- selenium启动firefox时加载扩展
有些时候,我们测试需要用到插件或者已经导入的证书(比如金融和安全加密行业),而selenium启动firefox时会打开一个新的,不含有任何插件和个人证书的firefox(等同于全新安装后第一次打开的 ...
- 7.解决在python中用selenium启动FireFox浏览器启动不了的方法
首次在利用python中的selenium启动FireFox浏览器时可能碰到如下问题 当输入如下代码时: from selenium import webdriver brower=webdriver ...
- selenium启动firefox打开导入向导问题解决
操作系统:win8-64位 火狐版本:40.0.2 问题描述:selenium启动firefox时,每次启动都提示我导入其他浏览器的页签,如下图所示 解决方法一: 到firefox的profiles. ...
- selenium启动firefox、ie、chrome各浏览器方法
1.启动firefox浏览器 a.如果你的本地firefox是默认路径安装的话,如下方式即可启动浏览器 WebDriver driver = new FirefoxDriver(); driver.g ...
- selenium各种场景下的启动Firefox
开始学习selenium时为了启动Firefox可谓费尽周折,在大神的帮助下才堪堪搞定,走出了selenium的第一步:jdk1.8 + selenium_2.46 + Firefox国际版40.0. ...
- Selenium在Firefox中踩过的
本文转至 http://www.51testing.com/html/11/n-3711311.html,作者对webdriver在Firefox中设置profile配置项挺熟的,是用Python实现 ...
- java selenium启动火狐浏览器报错:Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: VISTA Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:14.666Z
Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: VISTA Build in ...
随机推荐
- [LeetCode] 231. 2 的幂
位运算 231. 2 的幂 ``` class Solution { public boolean isPowerOfTwo(int n) { int cnt = 0; while (n>0) ...
- Linux系统挂载NFS文件系统
https://help.aliyun.com/document_detail/90529.html?spm=a2c4g.11186623.6.570.43212f30T5yM4w
- Go语言web开发---Beego的session
一.简介 Session是一段保存在服务器上的信息,当客户端第一次访问服务器时创建Session,同时也会创建一个名为beegosessionID,值为创建的Session的id的Cookie. 这个 ...
- Python+Selenium学习笔记10 - send_keys上传文件
在火狐浏览器上传文件 上传前,同一个HTML文件在火狐和Edge浏览器显示有些不同 这是Firefox浏览器的显示 这是Edge浏览器 上传后 1 # coding = utf-8 2 3 from ...
- 华为MDC自动驾驶
华为MDC自动驾驶 智能驾驶汽车中,包含四个核心子系统:传感器.计算平台.执行器与应用算法,华为MDC( Mobile Data Center: 移动数据中心)定位为智能驾驶的计算平台.此平台集成了华 ...
- ISP算法高水平分析(下)
ISP算法高水平分析(下) 十.LSC(Lens Shade Correction)------镜头阴影矫正 Lens Shading指画面四角由于入射光线不足形成的暗角,同时,由于不同频率的光折射 ...
- 尚硅谷Java——宋红康笔记【day1-day5】
day1 注释 1.java规范的三种注释方式: 单行注释 多行注释 文档注释(java特有) 2. 单行注释和多行注释的作用: ① 对所写的程序进行解释说明,增强可读性.方便自己,方便别人 ② 调试 ...
- selenium 隐式等待与显式等待
1.隐式等待:driver.implicitly_wait() driver = webdriver.Chrome()driver.implicitly_wait(10) #获取元素时最多会等 ...
- 九、Nginx常见问题处理
优化Nginx并发量 优化软件进程数.优化软件最大并发连接数限制.优化内核连接数限制open files(临时和永久同时设置) [root@proxy ~]# ab -n 2000 -c 2000 ...
- centos 7 iotop 安装
安装指令:yum -y install iotop 指定查看aubunt 用户的读写状态:iotop -u aubunt -P -k -t 允许在非交互模式下每隔3秒刷新一次,只刷新6次:iotop ...