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
Selenium应用代码(登录)相关推荐
- python自动输入账号密码_Python如何基于selenium实现自动登录博客园
这篇文章主要介绍了Python如何基于selenium实现自动登录博客园,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 需要做的准备: 本文章是使用 ...
- Python小姿势 - # Python网络爬虫之如何通过selenium模拟浏览器登录微博
Python网络爬虫之如何通过selenium模拟浏览器登录微博 微博登录接口很混乱,需要我们通过selenium来模拟浏览器登录. 首先我们需要安装selenium,通过pip安装: ``` pip ...
- Python 02 Selenium 账号密码登录CSDN
Python selenium 账号密码登录CSDN from time import sleep from selenium import webdriverdef login():url = 'h ...
- python+selenium移动滑块代码【杭州多测师_王sir】【杭州多测师】
淘宝登录场景python+selenium移动滑块代码 #coding=utf-8 import time from selenium import webdriver from selenium. ...
- Selenium QQ自动化登录
系列文章目录 第一篇:Java实现QQ登录 文章目录 系列文章目录 前言 登录 selenium登录 登录流程 selenium操作 获取登录数据 完整代码 总结 前言 本文内容仅供学习参考,禁止商业 ...
- 使用selenium模拟动态登录QQ邮箱爬取收件箱内容放在CSV文件中
获取收件箱列表信息就是使用selenium实现模拟登录.点击收件箱链接.获取收件箱列表的html过程,然后就是正常的查找数据 1.我们首先就是要登录到QQ邮箱中,然后找到收件箱的页面的,才能爬取到 ...
- 利用selenium模拟自动登录链家、贝壳、安居客等网站(超级实用,推荐收藏!)
大家好, 今天跟大家分享一个利用selenium模拟自动登录王连某家.an聚客等网站. 文章内容超级实用,尽快在小本本上记录下来哟. 特别说明,以下代码仅用于交流学习,不做其他商业用途,切记切记! 上 ...
- 用selenium模拟浏览器登录淘宝识别滑动验证码
用selenium模拟浏览器登录淘宝,使用账号密码的方式登录淘宝,但是在登录的时候遇到需要滑动验证,使用selenium模拟点击滑块,滑动验证码完成登录. 本文的代码现测可用.做个记录,方便以后查看. ...
- 使用selenium+chrome模拟登录天眼查将数据保存至excel
之前的博客中,为大家带来了使用selenium进行模拟登录,这次呢,为大家带来的是使用selenium进行模拟登录天眼查,然后抓取天眼查的前五页信息,由于不是会员,只能抓取前五页,你要是想要抓取更多, ...
- selenium 实现自动登录校网(网页版)
文章目录 selenium 实现自动登录校网 1.安装 python3.7 2.安装 selenium 3.安装 chrome 和驱动 4.定时任务 5.实现代码 selenium 实现自动登录校网 ...
最新文章
- 微信如何实施微服务?
- 最适合你性格的职业类型是什么?
- 受益匪浅:十个哲理寓言,十个成功秘诀
- 云计算将为移动医疗带来哪些新机遇?
- phpcms如何给已有的模块添加新功能?
- 【终极方法】解决IDEA搜索不到Lombok插件的问题(IDEA 不能识别 @Slf4j,@Getter ,@Setter注解)
- 【图像处理】——创建一个新的图片
- 【JS 逆向百例】37网游登录接口参数逆向
- mysql 数据库的维护,优化
- iOS /clang:-1: linker command failed with exit code 1 (use -v to see invocation) 报错
- python标注_python怎么标注
- 慕课网风袖小程序 一一第一阶段
- 中央财经大学c语言试题答案,中央财经大学C语言题
- 武士道的精神,就是死(转自知乎)
- java生成csr_使用Keytool工具生成CSR
- [C语言]倒序输出字符串
- html中repeat的作用,深入探究CSS repeat()函数知识及用法
- 【ZYNQ】那些年我们拿下了 Zynq
- Unity 报错处理
- vue中如何检测身份正反面_vue iview怎么验证身份证正则