`
雪馨25
  • 浏览: 128453 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

【selenium】selenium安装及验证

阅读更多

安装前提

  • jdk安装好
  • eclipse安装好
  • maven安装好

selenium安装

  • 在项目路径上新建文件夹seleniumtestP(E:\seleniumtestP),无中文
  • 新建文件Pom.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
            <modelVersion>4.0.0</modelVersion>
            <groupId>MySel20Proj</groupId>
            <artifactId>MySel20Proj</artifactId>
            <version>1.0</version>
            <dependencies>
                <dependency>
                    <groupId>org.seleniumhq.selenium</groupId>
                    <artifactId>selenium-java</artifactId>
                    <version>2.19.0</version>
                </dependency>
            </dependencies>
    </project>
    
  • 进入到命令行界面,进入到第三步建立的Pom.xml文件所在的路径(cd E:\seleniumtestP)
  • 执行命令mvn clean install
  • 执行成功后:项目下载完成,为了导入eclipse,执行转化命令 :mvn eclipse:eclipse
  • 将转化后的项目导入到eclipse中,file>import>existing projects into workspace,选择转化后的项目,点击确定导入。
  • 导入后项目会报错,以为引用的jar没有被加入索引路径。Window>preferences>Java>Build Path>Classpath Variables,点击new新建 name: M2_REPO path:maven的jar本地路径即(.m2/repository)
  • 确定后项目不再报错
  • 项目中建立源码文件夹:src(项目上右键,new,Source Folder)
  • 新建包,com.test和包下的java文件
  • 完成Java文件内容,并再联网的情况下运行。

 

public class Selenium2Example  {
    public static void main(String[] args) {
        // Create a new instance of the Firefox driver
        // Notice that the remainder of the code relies on the interface, 
        // not the implementation.
        WebDriver driver = new FirefoxDriver();
        // And now use this to visit Google
        driver.get("http://www.google.com");
        // Alternatively the same thing can be done like this
        // driver.navigate().to("​​http://www.google.com.hk");
        // Find the text input element by its name
        WebElement element = driver.findElement(By.name("q"));
        // Enter something to search for
        element.sendKeys("Cheese!");
        // Now submit the form. WebDriver will find the form for us from the element
        element.submit();
        // Check the title of the page
        System.out.println("Page title is: " + driver.getTitle());
        // Google's search is rendered dynamically with JavaScript.
        // Wait for the page to load, timeout after 10 seconds
        (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver d) {
                return d.getTitle().toLowerCase().startsWith("cheese!");
            }
        });

        // Should see: "cheese! - Google Search"
        System.out.println("Page title is: " + driver.getTitle());
        
        //Close the browser
        driver.quit();
    }
}

 

  • 正常运行即可

问题

  • 报错:Exception in thread "main"org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed.
  • 解决办法:指定firefox执行文件入系统属性。
       
    
     System.setProperty("webdriver.firefox.bin","D:/Program Files/Mozilla Firefox/firefox.exe");
           WebDriver driver =new FirefoxDriver();
    

学习地址:

  • 另一学习:

selenium-ide安装及验证

分享到:
评论

相关推荐

    ,selenium IDE安装包及离线安装教程

    在"标题"中提到的"Selenium IDE安装包及离线安装教程",指的是在不能直接从网上下载Selenium IDE的情况下,通过获取已准备好的离线安装包来完成安装的过程。这通常涉及到下载一个包含安装文件(如`selenium-ide-...

    Selenium安装配置及使用

    安装完成后,通过菜单栏的"工具" &gt; "Selenium-IDE"启动,然后尝试录制一些动作来验证安装是否成功。 2. **导出测试脚本**: 你可以通过"文件" &gt; "Export Test Case as"将录制的脚本导出为多种编程语言的代码。 3. *...

    Selenium IDE的安装

    ### Selenium IDE的安装详解 #### 一、简介 Selenium IDE是一款基于Firefox浏览器的插件,主要用于自动化Web应用测试。用户可以通过简单的操作录制测试用例,并进行回放以验证Web应用的功能是否符合预期。本文将...

    滑块验证通过selenium爬取京东代码

    滑块验证,通过selenium,爬取京东代码

    01-Selenium环境的安装与配置.pptx

    综上所述,本文介绍了如何从零开始搭建Selenium测试环境,包括Python、Eclipse + PyDev、Selenium本身的安装配置以及浏览器驱动的配置与验证等关键步骤。通过这些步骤,用户可以轻松构建起一个完整的自动化测试环境...

    Selenium IDE介绍安装使用

    1. **安装Python Selenium库:** 使用pip命令`pip install selenium`来安装Selenium库。 2. **WebDriver:** 需要对应浏览器的WebDriver,例如ChromeDriver或GeckoDriver(Firefox)。 3. **编写Python脚本:** 将...

    selenium安装使用说明

    **Selenium 安装与使用指南** Selenium 是一款强大的 Web 自动化测试工具,它允许开发者编写脚本来模拟用户在浏览器中的各种交互行为。这篇详细的指南将带你一步步了解 Selenium 的安装过程,并通过实例讲解其基本...

    seleniumRC

    Selenium RC允许测试者通过编程语言(如Java、Python、Ruby等)编写测试脚本,然后控制浏览器进行交互,以此验证网页的功能和行为。 **一、Selenium RC的基本原理** Selenium RC由两个主要部分组成:服务器(Server...

    淘宝商品爬虫, selenium破解滑块验证(目前可用)

    淘宝商品爬虫与Selenium破解滑块验证是网络爬虫技术在电商领域的应用,涉及到的主要知识点包括Python编程、网络爬虫原理、Selenium库的使用以及动态验证码的破解策略。以下将详细介绍这些内容。 首先,Python编程是...

    Selenium_v2.5

    Selenium 是一个强大的开源自动化测试框架,用于...无论是对于开发者验证代码功能,还是质量保证团队进行系统测试,都是不可或缺的工具。学习和掌握Selenium_v2.5的相关知识,对于提升软件测试的专业技能具有重要意义。

    Selenium

    ### Selenium 知识点详解 #### 一、Selenium 概述 Selenium 是一个用于自动化 Web 应用程序测试的...通过本文的介绍,希望能够帮助大家更好地理解 Selenium 的基本原理及使用方法,进一步提升软件测试的质量和效率。

    selenium通过代理身份验证

    selenium通过代理身份验证

    selenium-ide-2.5.0功能测试组件及安装步骤

    **Selenium IDE 2.5.0 功能测试组件及安装步骤** Selenium IDE 是一个强大的自动化测试工具,尤其在Web应用的功能测试方面表现出色。它作为Firefox浏览器的一个插件,能够录制、编辑和回放用户操作,为软件测试...

    Selenium_IDE_官方文档翻译.pdf

    通过本文档,读者可以学习如何安装和启动 Selenium IDE,如何使用 Selenium IDE 创建和运行测试用例,如何使用 Selenese 脚本语法编写测试套件等。 一、Selenium IDE 的安装和启动 Selenium IDE 可以从 SeleniumHQ...

    Selenium-Python中文手册

    要安装Selenium Python支持库,首选方法是从PyPI官方库下载或使用`pip`命令进行安装。对于Python3.5及以上版本,`pip`是标准库的一部分,可以使用以下命令进行安装: ```bash pip install selenium ``` **1.2 ...

    python 实现selenium断言和验证的方法

    ### Python 实现 Selenium 断言和验证的方法 在自动化测试领域,Selenium 是一款非常流行的工具,它能够帮助开发者和测试工程师模拟用户操作浏览器的行为,从而实现自动化测试的目的。Python 作为一门简单易学且...

Global site tag (gtag.js) - Google Analytics