本文示例使用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版)的更多相关文章

  1. Selenium启动Firefox示例(python版)

    目前做selenium自动化使用的主流语言分为java和python,前一篇为java版,本篇介绍python实现selenium启动Firefox. 1 #-*- coding:utf-8 -*- ...

  2. selenium启动Firefox失败

    今天搭建java+selenium环境,搭建几次都失败,总结一下原因 1. selenium启动Firefox,不需要额外的driver 2. Friefox如果没有安装到默认路径C盘,代码中需要修改 ...

  3. selenium启动firefox时加载扩展

    有些时候,我们测试需要用到插件或者已经导入的证书(比如金融和安全加密行业),而selenium启动firefox时会打开一个新的,不含有任何插件和个人证书的firefox(等同于全新安装后第一次打开的 ...

  4. 7.解决在python中用selenium启动FireFox浏览器启动不了的方法

    首次在利用python中的selenium启动FireFox浏览器时可能碰到如下问题 当输入如下代码时: from selenium import webdriver brower=webdriver ...

  5. selenium启动firefox打开导入向导问题解决

    操作系统:win8-64位 火狐版本:40.0.2 问题描述:selenium启动firefox时,每次启动都提示我导入其他浏览器的页签,如下图所示 解决方法一: 到firefox的profiles. ...

  6. selenium启动firefox、ie、chrome各浏览器方法

    1.启动firefox浏览器 a.如果你的本地firefox是默认路径安装的话,如下方式即可启动浏览器 WebDriver driver = new FirefoxDriver(); driver.g ...

  7. selenium各种场景下的启动Firefox

    开始学习selenium时为了启动Firefox可谓费尽周折,在大神的帮助下才堪堪搞定,走出了selenium的第一步:jdk1.8 + selenium_2.46 + Firefox国际版40.0. ...

  8. Selenium在Firefox中踩过的

    本文转至 http://www.51testing.com/html/11/n-3711311.html,作者对webdriver在Firefox中设置profile配置项挺熟的,是用Python实现 ...

  9. 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 ...

随机推荐

  1. Windows登录服务器CLI运行脚本出现 syntax error: unexpected end of file 错误的解决

    0.前言 通常我们在编辑 Linux 服务器上的文件时,直接在 Linux 环境比较麻烦(当然熟练使用 VIM 的程序员除外哈哈),有时我们会使用 Windows 将文件编辑好再上传到服务器端,我用的 ...

  2. 【MybatisPlus】数据库的datetime类型字段为空的时候,报错空指针?

    一.发现经历 事情是这样的,我今天本来要演示系统,就去前端同学的页面上点一点.不小心点到了其他同事编写的服务,然后界面就报错了.这给我吓得,这还能演示吗这.然后,我就去服务器查看了一下日志,发现了如下 ...

  3. DM8_Linux详细安装步骤

    (从虚拟机配置讲起,有基础的可以直接看二,谢谢) 一.虚拟机的安装和配置 软件:virtualbox 系统:centos7 工具:Xshell 官网下载centos7,使用virtualbox安装ce ...

  4. [Distributed ML] Parameter Server & Ring All-Reduce

    Resource ParameterServer入门和理解[较为详细,涉及到另一个框架:ps-lite] 一文读懂「Parameter Server」的分布式机器学习训练原理 并行计算与机器学习[很有 ...

  5. Python发送SMTP邮件指南

      SMTP(Simple Mail Transfer Protocol)简单邮件传输协议,Python内置对SMTP的支持,可以发送纯文本文件,HTML邮件以及附带文件.   一.两个模块 Pyth ...

  6. 用golang刷LeetCode

    用golang刷LeetCode 用Go语言刷LeetCode记录,只是为了练习Go语言,能力有限不保证都是最优解,只能在此抛转引玉了. 数据结构和算法 数据结构和算法是程序员的命根子,没了命根子也就 ...

  7. TensorFlow分布式在Amazon AWS上运行

    TensorFlow分布式在Amazon AWS上运行 Amazon AWS 提供采用 NVIDIA K8 GPU 的 P2.x 机器.为了能够使用,第一步还需要创建一个 Amazon AWS 账户, ...

  8. NeuWare软件开发环境

    NeuWare软件开发环境 NeuWare 全面支持各类主流编程框架(如TensorFlow,Caffe,Caffe2,MXNet和ONNX等).用户可面向上述编程框架,便捷地在MLU100上开发和部 ...

  9. CodeGen处理Synergy方法目录

    CodeGen处理Synergy方法目录 如果Synergy应用程序开发环境包括使用Synergy/DE xfServerPlus,则可以基于Synergy方法目录中包含的元数据生成代码.要启用此功能 ...

  10. 这款拓展让你的jupyter lab更高效

    有一段时间没有分享过有关jupyter lab的内容了,今天给大家介绍一款实用的jupyter lab插件,可以帮助我们打造更灵活易用的jupyter lab. 图1 这款拓展的名称叫做jlab-en ...