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


}

转载于:https://www.cnblogs.com/testwang/p/5286681.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值