selenium 打开浏览器
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
// 如果你的 FireFox 没有安装在默认目录,那么必须在程序中设置
// System.setProperty("webdriver.firefox.bin", "D:\\Program Files\\Mozilla Firefox\\firefox.exe");
// 创建一个 FireFox 的浏览器实例
WebDriver driver = new FirefoxDriver(); // 让浏览器访问 Baidu
driver.get("http://www.baidu.com");
// 用下面代码也可以实现
// driver.navigate().to("http://www.baidu.com"); // 获取 网页的 title
System.out.println("1 Page title is: " + driver.getTitle()); // 通过 id 找到 input 的 DOM
WebElement element = driver.findElement(By.id("kw")); // 输入关键字
element.sendKeys("ZTree"); // 提交 input 所在的 form
element.submit(); // 通过判断 title 内容等待搜索页面加载完毕,Timeout 设置10秒
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().endsWith("Ztree");
}
}); // 显示搜索结果页面的 title
System.out.println("2 Page title is: " + driver.getTitle()); //关闭浏览器
driver.quit(); /* WebDriver driver = new FirefoxDriver(); Navigation navigation = driver.navigate();
navigation.to("https://www.baidu.com"); WebElement subox = driver.findElement(By.id("kw"));
subox.sendKeys("景甜长城剧照");
WebElement subtn = driver.findElement(By.id("su"));
subtn.click(); try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
} driver.close();
*/
selenium 打开浏览器的更多相关文章
- java+selenium打开浏览器实现后台静默运行
简介:java selenium搭建无界面浏览器 PhantomJS是一个基于Webkit的"无界面"(headless)浏览器,它会把网站加载到内存并执行页面上的JavaScri ...
- 1 Selenium打开浏览器
[环境] Selenium3.0.1+Python3.6+unittest win7+IE10 1.打开FireFox浏览器 import unittest from selenium import ...
- python+selenium打开浏览器报错问题
报关键字,升级selenium版本 若打开IE浏览器,停在IE界面,无法跳转对应的地址,设置一下IE的页面缩放,设置为100%
- python+selenium打开浏览器
Firefox(高版本要安装换火狐驱动,47版本以下可不安装) GoogleChrome(需要安装浏览器的驱动插件,驱动到selenium官网下载,目前该浏览器的驱动只有32位的,所以Google安装 ...
- selenium 打开浏览器报错java.lang.NoSuchMethodError: org.openqa.selenium.chrome.ChromeOptions.addArguments([Ljava/lang/String;)
java.lang.NoSuchMethodError: org.openqa.selenium.chrome.ChromeOptions.addArguments([Ljava/lang/Strin ...
- selenium自动化打开浏览器不受信任解决办法
之前在用selenium(火狐浏览器)打开一个https网站时,总是弹出不受信任,修改配置后,每次加载的浏览器都是还原了配置,无法加载出页面,这里给出解决办法:让浏览器去加载我们修改后的配置,具体如下 ...
- (四)selenium打开和关闭浏览器
一.Selenium简介 Selenium3.0主要变更特性: ①移除seleniumRC ②FireFox和Safari推出了自己的driver(geckodriver 和 Safaridriver ...
- Python+selenium打开或关闭浏览器
Python+selenium打开或关闭浏览器 一.打开或关闭火狐浏览器 1. 初始化一个webdriver实例对象driver,然后打开和关闭firefox浏览器.要用selenium打 ...
- Selenium入门系列1 打开浏览器访问网页,退出浏览器
对于功能自动化的理解就是用测试工具替代手工.手工怎么操作的,工具也如何操作. 手工测试:在前置条件下,执行一定的操作步骤>与预期结果对比 功能自动化:在前置条件下,识别对象 >操作对象&g ...
随机推荐
- jQuery Validate 表单验证 — 用户注册简单应用
相信很多coder在表单验证这块都是自己写验证规则的,今天我们用jQuery Validate这款前端验证利器来写一个简单的应用. 可以先把我写的这个小demo运行试下,先睹为快.猛戳链接--> ...
- Oracle学习笔记五 SQL命令(三):Group by、排序、连接查询、子查询、分页
GROUP BY和HAVING子句 GROUP BY子句 用于将信息划分为更小的组每一组行返回针对该组的单个结果 --统计每个部门的人数: Select count(*) from emp group ...
- 【转】MySql中的函数
原文:http://www.cnblogs.com/kissdodog/p/4168721.html MySQL数据库提供了很多函数包括: 数学函数: 字符串函数: 日期和时间函数: 条件判断函数: ...
- Linux基础练习题
1.列出当前系统上所有已经登录的用户名,注意:同一个用户登录多次,则只显示一次即可. [root@bj-1-160-enzhi ~]# who|cut -d ' ' -f 1|uniq -c 2 ro ...
- kd树和knn算法的c语言实现
基于kd树的knn的实现原理可以参考文末的链接,都是一些好文章. 这里参考了别人的代码.用c语言写的包括kd树的构建与查找k近邻的程序. code: #include<stdio.h> # ...
- 基于UDP的网络编程
与TCP编程相比较,UDP缺少了connect().listen()及accept()函数,这是由于UDP协议无连接的特性,不用维护TCP的连接.断开等状态. UDP编程框图 API函数 socket ...
- Mellanox 8亿美元收购EZchip
http://www.iccsz.com/site/cn/News/2015/10/08/20151008003916131771.htm Mellanox 8亿美元收购EZchip 目标电信运营商 ...
- [No00009A]JsonToObject json与类互转
using System.Web.Script.Serialization; /// <summary> /// 内部类,保存jsonData /// </summary> p ...
- [LeetCode] Remove Element 移除元素
Given an array and a value, remove all instances of that value in place and return the new length. T ...
- 【svn】在提交文件是报错:previous operation has not finished;run 'cleanup' if it was interrupted
1.svn在提交文件是报错:previous operation has not finished;run 'cleanup' if it was interrupted2.原因,工作队列被占用,只需 ...