zoukankan      html  css  js  c++  java
  • Selenium应用代码(登录)

    这篇可以不看,主要是为了以后的应用代码(传参)做铺垫。

    import java.awt.Rectangle;

    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.text.SimpleDateFormat;
    import java.util.Date;

    import javax.imageio.ImageIO;

    import org.openqa.selenium.By;
    import org.openqa.selenium.Point;
    import org.openqa.selenium.TakesScreenshot;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.interactions.Actions;
    import java.io.File;
    import java.io.IOException;
    import org.apache.commons.io.FileUtils;
    import org.openqa.selenium.OutputType;
    import org.openqa.selenium.TakesScreenshot;

    public class Login {
    public static int t = 1;


    static WebDriver driver = new ChromeDriver();


    public void Loginindex(String url,String user,String pass) throws InterruptedException{

    driver.get(url);

    // 用下面代码也可以实现
    // driver.navigate().to("url");
    // 获取 网页的 title
    // System.out.println("1 Page title is: " + driver.getTitle());
    // 通过 id 找到 input 的 DOM
    // try{
    // WebElement element0 =driver.findElement(By.xpath("//div[contains(@class,'user-info-mission-luckdraw-mask-body-close')]"));
    // element0.click();
    // }catch(Exception e){
    // System.out.println("广告没有了");
    // //System.exit(0);
    // }
    WebElement element = driver.findElement(By.xpath("//button[contains(@class,'Login')]"));
    // 输入关键字
    element.click();
    Thread.sleep(3000);
    WebElement frame = driver.findElement(By.xpath("//*[@id='C_maijia-login']/div/div/div/iframe"));
    driver.switchTo().frame(frame);
    WebElement element1 =driver.findElement(By.xpath("//input[@name='loginCode']"));
    element1.sendKeys(user);
    WebElement element2 =driver.findElement(By.xpath("//input[@name='loginPassword']"));
    element2.sendKeys(pass);;
    WebElement button =driver.findElement(By.xpath("//button[contains(.,'登录')]"));
    button.click();
    }


    }

  • 相关阅读:
    2020-12
    知识的深度跟知识的广度
    限额类费用报销单N+1原则
    用友实习总结
    NC57,NC63-NC二开经验总结
    union和union all的区别
    2020
    mark_rabbitMQ
    营销之路
    怎么对ORACLE里的CLOB字段进行模糊查询
  • 原文地址:https://www.cnblogs.com/testwang/p/5286681.html
Copyright © 2011-2022 走看看