天天看点

Selenium + Java 自动化测试

  1. 详解介绍Selenium常用API的使用–Java语言(完整版) ---- 浏览器驱动下载
  2. Selenium之cannot find Chrome binary错误
  3. JAVA+selenium+tess4j识别登陆验证码 (只能识别简单的验证码图片)
  4. 登录QQ邮箱测试,如下

登录QQ邮箱测试代码如下:

<dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>
           
package com.wj.selenium;

import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class Itest {

    private static final ChromeDriver driver;
    static {
        System.setProperty("webdriver.chrome.driver","F:\\JavaDevelop\\chromedriver_win32\\chromedriver.exe");
        ChromeOptions option = new ChromeOptions();
        option.setBinary("F:\\ChromeCore\\ChromeCore.exe");
        driver = new ChromeDriver(option);
    }

    public static void main(String[] args) throws Exception {
        try {
            driver.get("https://mail.qq.com/");
            driver.switchTo().frame("login_frame");//定位登录的iframe
            //driver.findElement(By.id("u")).sendKeys("XXXXXX");
            driver.findElementById("u").sendKeys("XXXXXX");
            driver.findElementById("p").sendKeys("XXXXXX");
            driver.findElementById("login_button").click();
            System.out.println(driver.getCurrentUrl());
            Thread.sleep(10000);
        }finally {
            driver.quit();
        }
    }
}


           

继续阅读