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 打开浏览器的更多相关文章

  1. java+selenium打开浏览器实现后台静默运行

    简介:java selenium搭建无界面浏览器 PhantomJS是一个基于Webkit的"无界面"(headless)浏览器,它会把网站加载到内存并执行页面上的JavaScri ...

  2. 1 Selenium打开浏览器

    [环境] Selenium3.0.1+Python3.6+unittest win7+IE10 1.打开FireFox浏览器 import unittest from selenium import ...

  3. python+selenium打开浏览器报错问题

    报关键字,升级selenium版本 若打开IE浏览器,停在IE界面,无法跳转对应的地址,设置一下IE的页面缩放,设置为100%

  4. python+selenium打开浏览器

    Firefox(高版本要安装换火狐驱动,47版本以下可不安装) GoogleChrome(需要安装浏览器的驱动插件,驱动到selenium官网下载,目前该浏览器的驱动只有32位的,所以Google安装 ...

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

  6. selenium自动化打开浏览器不受信任解决办法

    之前在用selenium(火狐浏览器)打开一个https网站时,总是弹出不受信任,修改配置后,每次加载的浏览器都是还原了配置,无法加载出页面,这里给出解决办法:让浏览器去加载我们修改后的配置,具体如下 ...

  7. (四)selenium打开和关闭浏览器

    一.Selenium简介 Selenium3.0主要变更特性: ①移除seleniumRC ②FireFox和Safari推出了自己的driver(geckodriver 和 Safaridriver ...

  8. Python+selenium打开或关闭浏览器

    Python+selenium打开或关闭浏览器 一.打开或关闭火狐浏览器 1.       初始化一个webdriver实例对象driver,然后打开和关闭firefox浏览器.要用selenium打 ...

  9. Selenium入门系列1 打开浏览器访问网页,退出浏览器

    对于功能自动化的理解就是用测试工具替代手工.手工怎么操作的,工具也如何操作. 手工测试:在前置条件下,执行一定的操作步骤>与预期结果对比 功能自动化:在前置条件下,识别对象 >操作对象&g ...

随机推荐

  1. Elixir 1.0 Release

    如期而至,9.9苹果产品发布会之后,紧接着在今天(教师节)我们终于等到了Elixir 1.0,苹果范儿的说法是:Now,Elixir 1.0 is here   注意:官网上的链接说明之类还没有更新过 ...

  2. pscp工具上传或取回文件、文件夹

    1.把服务器上的/root/dir目录取回本地"C:\My Documents\data\"目录 C:\>pscp.exe -r root@IP:/root/dir &quo ...

  3. mongodb 3.x 之实用新功能窥看[2] ——使用$lookup做多表关联处理

    这篇我们来看mongodb另一个非常有意思的东西,那就是$lookup,我们知道mongodb是一个文档型的数据库,而且它也是最像关系型数据库的 一种nosql,但是呢,既然mongodb是无模式的, ...

  4. Win10全屏看视频时任务栏不隐藏

    解决办法: 1.对任务栏鼠标右键点击,选择"任务管理器" 2.在进程选项下找到Windows进程中的Windows资源管理器 3.对Windows资源管理器鼠标右键,选择重新启动

  5. mongodb 速成笔记

    以下环境为mac osx + jdk 1.8 + mongodb v3.2.3 一.安装 brew安装方式是mac下最简单的方式 brew update brew install mongodb 其它 ...

  6. [LeetCode] H-Index 求H指数

    Given an array of citations (each citation is a non-negative integer) of a researcher, write a funct ...

  7. [LeetCode] Decode Ways 解码方法

    A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...

  8. Ajax入门(三)

    get和post请求 1,get方式: 在url地址后面以请求字符串(传递的get参数信息)形式传递数据.    例: aj.open('get','./03.php?name=3tu'); 在传递特 ...

  9. c#datagridview

    //保证显示当前活动单元格 this.Invoke(new Action(() => { dataGridView1.CurrentCell = dataGridView1.Rows[index ...

  10. 详解三种缓存过期策略LFU,FIFO,LRU(附带实现代码)

    在学操作系统的时候,就会接触到缓存调度算法,缓存页面调度算法:先分配一定的页面空间,使用页面的时候首先去查询空间是否有该页面的缓存,如果有的话直接拿出来,如果没有的话先查询,如果页面空间没有满的时候, ...