怎么将selenium 对应eclipse类库引入eclipse

博客分类:
1. Install Selenium IDE as a plugin of firefox browser.
You'd better download the latest one from
2. Create a java file "fromide.java" in your eclipse project as below structure.
This file should be empty at this time.
3. Start it to record a script about any operation.
4. Save it to fromide.java in your eclipse project as Junit4 code.
Cover the existing one.
5. Open it in Eclipse.
Remember it's unavailable now.
6. Define selenium variable as below.
In order to make it available.
package com.example.
import com.thoughtworks.selenium.*;
import org.junit.Aimport org.junit.Bimport org.junit.Timport java.util.regex.P
public class fromide { private DefaultS // Notice: This line should be added manually.
@Before public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "");
selenium.start(); }
@Test public void testFromide() throws Exception {
selenium.open("/");
selenium.type("id=kw", "asd");
selenium.type("id=kw", "selenium webdriver");
selenium.waitForPageToLoad("30000");
selenium.click("//table[@id='1']/tbody/tr/td/h3/a/font[2]"); }
@After public void tearDown() throws Exception {
selenium.stop(); }}
7. Run it.
It would simulate your operation per Eclipse.
That's what we need.
Then we can modify and utilize it in Eclipse.
It's a professional way to develop selenium Java code.
Record the code by Selenium IDE first, then develop it in Eclipse to make it more comfortable as you want.
lihuaiyuan84
浏览: 4307 次
来自: 上海
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'selenium+eclipse搭建及编写第一个test代码2(WebDriver) - CSDN博客
selenium+eclipse搭建及编写第一个test代码2(WebDriver)
首先要有:
1、eclipse+jdk
2、selenium-IDE(http://release.seleniumhq.org/)
3、Firefox
4、selenium-java-2.53.1.jar(好像不是必须的)
5、selenium-server-standalone-2.53.1.jar
selenium-IDE使用方法、selenium代码转换java及eclipse创建我另一篇博客有提及:
selenium下载地址:
Java/JUnit 4/Remote Control
之前在selenium-IDE转换的代码格式为:Java/JUnit4/Remote Control
该格式在eclipse中运行需在build path中至少添加selenium-server-standalone-2.53.1.jar
且在运行test时需要运行selenium-server-standalone-2.53.1.jar才能进行测试
java -jar selenium-server-standalone-2.53.1.jar
Java/JUnit 4/WebDriver
使用以上格式的java代码在eclipse中运行需要在build path中添加selenium-server-standalone-2.53.1.jar
但是在运行test时不需要运行jar包,直接点击Run就可以了
想要查看selenium的各种方法,可以添加对应版本的source code:
下载地址:
具体方法可以参考:
1、使用selenium-IDE编辑脚本
以下为打开baidu首页,输入“selenium”,点击进行查询,最后验证一下有没有期望显示的文字“Selenium - Web Browser Automation”
2、转换脚本格式-Java/JUnit 4/WebDriver
3、复制生成的代码至eclipse新建的同名java文件中
eclipse路径如下:
DriverTest.java为刚新建的java文件,selenium-server-standalone-2.53.1.jar必须添加到build path
以下为复制到DriverTest.java的代码,需要修改package和class名
package selenium.
import java.util.regex.P
import java.util.concurrent.TimeU
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxD
import org.openqa.selenium.support.ui.S
public class DriverTest {
private WebD
private String baseU
private boolean acceptNextAlert =
private StringBuffer verificationErrors = new StringBuffer();
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = &/&;
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
public void testUntitled2() throws Exception {
driver.get(&&);
// ERROR: Caught exception [ERROR: Unsupported command [setSpeed | 500 | ]]
driver.findElement(By.id(&kw&)).clear();
driver.findElement(By.id(&kw&)).sendKeys(&selenium&);
driver.findElement(By.id(&su&)).click();
assertEquals(&Selenium - Web Browser Automation&, driver.findElement(By.xpath(&//div[@id='1']/h3/a[1]&)).getText());
} catch (Error e) {
verificationErrors.append(e.toString());
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!&&.equals(verificationErrorString)) {
fail(verificationErrorString);
private boolean isElementPresent(By by) {
driver.findElement(by);
} catch (NoSuchElementException e) {
private boolean isAlertPresent() {
driver.switchTo().alert();
} catch (NoAlertPresentException e) {
private String closeAlertAndGetItsText() {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
alert.dismiss();
return alertT
} finally {
acceptNextAlert =
直接点击Run执行
本文已收录于以下专栏:
相关文章推荐
在Eclipse建立Selenium项目步骤如下
在下载Eclipse之前最好配置好java环境变量,可参考我之前的博客有图有真相java环境变量配置指南Eclipse安装指南下载完安装包后直接傻瓜式安装就行了之后我们就可以用Eclipse来启动用代...
第一步 安装JDK
下载地址:/technetwork/java/javase/downloads/jdk7-downloads-1880...
1)确保安装jdk,eclipse,Firefox
selenium运行自动化脚本(验证通过)
( 20:58:07)
分类:Java学习
项目顾问建议用...
之前电脑已经安装了jdk 和eclipse,只需要再下载selenium 相关程序即可。
1.Selenium IDE
    下载后的文件为selenium-ide-1.10.0.xpi,打开...
WebDriver在eclipse环境下的搭建
Eclipse 中配置webdriver
前年有搭建环境Eclipse下webdriver的环境,并写了几百个case,当时相当兴奋,学习Selenium的好多方法。结果今天再用时,别说怎么编写,就连...
今天总结下selenium的下拉选择框。我们通常会遇到两种下拉框,一种使用的是html的标签select,另一种是使用input标签做的假下拉框。后者我们通常的处理方式与其他的元素类似,点击或使用JS...
如果有任何问题,欢迎加QQ : 128 623 8812  交流。  我 也是刚开始用 自动化测试,共同进步,共同提高。
selenium 官网 IDE 等一系列 下载地址:http://www....
他的最新文章
讲师:宋宝华
讲师:何宇健
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)selenium集成到eclipse的方法_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
selenium集成到eclipse的方法
阅读已结束,下载文档到电脑
想免费下载更多文档?
定制HR最喜欢的简历
下载文档到电脑,方便使用
还剩6页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢搭建selenium+Python+eclipse 的开发环境 - GreenBean - 博客园
下载安装Python,下载&python-2.7.9.msi&后可直接安装
下载安装setuptools,下载setuptools-11.3.1后,用命令提示符转到安装包中setup.py所在的位置,执行setup.py install,进行安装
下载安装pip工具,下载pip-6.0.6后,用命令提示符转到安装包中setup.py所在的位置,执行setup.py install,进行安装
下载安装selenium,下载selenium-2.44.0,用命令提示符转到安装包中setup.py所在的位置,执行setup.py install,进行安装
下载浏览器驱动,下载IEDriverServer.exe,与python.exe在同一目录下就可以了
安装java jdk 并配置环境变量,下载安装jdk-6u43-windows-i586.exe,并配置环境变量
下载eclipse,直接解压后就能用
下载安装PyDev+2.7.1,解压后里面有plugins和features两个文件夹
建一个名为eclipse的文件夹,把上面的两个文件夹放入其中
再建一个名为WBPro的文件夹,把刚才的eclipse文件夹放入其中,插件的大致结构如:WBPro/eclipse /{plugins,features}
找到你的eclipse ,在其下建两个文件夹,一个是extplugins,一个是links,结构如{eclipse/extplugins,links},&
在links文件夹下,建立一个txt文本,在里面写入:path=extplugins/WBPro,注意是&/&,而不是&\&,再把文本文件命名为WBPro.link,注意全名是WBPro.link,&而不是WBPro.link.txt
启动eclipse,在菜单栏点击window-&Preferences,在弹出来的对话框中,看左边的导航栏,如果里面有你的插件名,如WBPro,恭喜你插件安装成功!
PyDev安装好之后,需要配置解释器。
  1.& 在 Eclipse 菜单栏中,选择Window & Preferences & Pydev & Interpreter & Python&New,输入名字和Python.exe所在安装路径,添加已安装的解释器
    2.& 点击Ok,跳出一个有很多复选框的窗口,选择需要加入SYSTEM pythonpath的选项
&&&&&&&&&&&&&&&&&&&
    3.& 一般可以采用默认设置,点击Ok。
    4.& 点击OK,保存配置
  10.& 接下来,创建一个python项目。  
    1.& 进入 Pydev 透视图,在 Eclipse 菜单栏中,选择 File & New & Project & Pydev & Pydev Project,新建项目:PyCase,单击 Next。
    注意:如果在创建项目的时候没有选中&Create default src folder and add it to the pythonpath&复选框,则需要通过 File & New & Other & Source Folder 手动创建一个源代码文件夹src。
    2.& 点击finish,如下
  3.进入 Pydev 透视图,在 Python Package Explorer 中,右键单击 src,选择 New-&Pydev Package,输入 Package 名称Py
   4.& 单击 Finish,Python 包就创建好了,此时,自动生成__init__.py 文件,该文件不包含任何内容。&&&&
&&&&&&&&&&&&&&&&&&&
    5.& 创建完 Pydev Package 后,右键单击创建的包Py27,选择 New-&Pydev Module,输入模块名称PyCase1.py Finish。这样,Python 模块就建成了
  11.& 写个小东西保存为PyCase1.py后按F11,选择Python run 执行脚本
# -*- coding: utf-8 -*-
from selenium import webdriver
import time
driver = webdriver.Ie()
driver.get('')
driver.implicitly_wait(20)
driver.find_element_by_id('kw').send_keys(&aa&)
driver.find_element_by_id('su').click()
time.sleep(5)
driver.quit()
  12.& 好了,大功告成

我要回帖

更多关于 eclipse导入selenium 的文章

 

随机推荐