天天看點

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();
        }
    }
}


           

繼續閱讀