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 ...
随机推荐
- nignx反向代理web服务器的配置与使用
一.为什么要用nignx反向代理 1.负载均衡 当一台服务器的单位时间内的访问量越大时,服务器压力就越大,大到超过自身承受能力时,服务器就会崩溃.为了避免服务器崩溃,让用户有更好的体验,我们通过负载均 ...
- Could not get JDBC Connection排查
最近在维护的一个比较旧的项目,发现总是隔一段时间JDBC就报错: Could not get JDBC Connection; nested exception is org.apache.commo ...
- 改造 Firefox 浏览器——GitHub 热点速览
作者:HelloGitHub-小鱼干 上周推荐了一个可以在浏览器上用 VS Code 的项目,这次 Firefox-UI-Fix 带你给 Firefox 来个大变身,在它现有 Proton UI 下进 ...
- 广播 (broadcasting)
广播 (broadcasting) 飞桨(PaddlePaddle,以下简称Paddle)和其他框架一样,提供的一些API支持广播(broadcasting)机制,允许在一些运算时使用不同形状的张量. ...
- GPU编程和流式多处理器(三)
GPU编程和流式多处理器(三) 3. Floating-Point Support 快速的本机浮点硬件是GPU的存在理由,并且在许多方面,它们在浮点实现方面都等于或优于CPU.全速支持异常可以根据每条 ...
- 关于Numba的线程实现的说明
关于Numba的线程实现的说明 由Numbaparallel目标执行的工作由Numba线程层执行.实际上,"线程层"是Numba内置库,可以执行所需的并发执行.在撰写本文时,有三个 ...
- python_selenium 之yaml文件读取(以读取元素信息为例)
一.yaml源文件编写 二.对yaml文件内容的读取 #coding=gbkimport osimport yamlcurrent_path=os.path.dirname(__file__)yaml ...
- 一文带你.Net混合锁和lock语句
本文主要讲解.Net基于Monitor.Enter和lock实现互斥锁 Monitor.Enter实现 相比前面的锁来说,混合锁的性能更高,任何引用类型的对象都可以做为锁对象,不需要事先创建指定类型的 ...
- 备份schema并排除大表到ASM磁盘上
1.查出占用空间比较大的表 select owner,segment_name,segment_type,bytes/1024/1024 mb from dab_segment where owner ...
- Vue指令实现原理
前言 自定义指令是vue中使用频率仅次于组件,其包含bind.inserted.update.componentUpdated.unbind五个生命周期钩子.本文将对vue指令的工作原理进行相应介绍, ...