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

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

}

Selenium应用代码(登录)的更多相关文章

  1. SharePoint2010 自定义代码登录方法

    转:http://yysyb123.blog.163.com/blog/static/192050472011382421717/ SharePoint2010 自定义代码登录方法 (自定义Form验 ...

  2. python+selenium模拟京东登录后台

    python+selenium模拟京东登录后台 import json from time import sleep from selenium import webdriver #from sele ...

  3. Selenium应用代码(读取mysql表数据登录)

    1. 封装链接数据库的类: import java.sql.ResultSet; import java.sql.Connection; import java.sql.DriverManager; ...

  4. [Python爬虫] Selenium实现自动登录163邮箱和Locating Elements介绍

    前三篇文章介绍了安装过程和通过Selenium实现访问Firefox浏览器并自动搜索"Eastmount"关键字及截图的功能.而这篇文章主要简单介绍如何实现自动登录163邮箱,同时 ...

  5. Selenium+Python ---- 免登录、等待、unittest单元测试框架、PO模型

    1.免登录在进行测试的过程中难免会遇到登录的情况,给测试工作添加了工作量,本文仅提供一些思路供参考解决方式:手动请求中添加cookies.火狐的profile文件记录信息实现.人工介入.万能验证码.去 ...

  6. python控制selenium点击登录按钮时报错 unknown error: Element is not clickable at point

    利用python控制selenium进行一个网页的登录时报错: C:\Users\Desktop\selenium\chrome>python chrome.py selenium.common ...

  7. 5、Selenium+Python自动登录163邮箱发送邮件

    1.Selenium实现自动化,需要定位元素,以下查看163邮箱的登录元素 (1)登录(定位到登录框,登录框是一个iframe,如果没有定位到iframe,是无法定位到账号框与密码框) 定位到邮箱框( ...

  8. Selenium网页自动登录项目(基于Python从0到1)

    Selenium是一个自动化测试工具,利用它我们可以驱动浏览器执行特定的动作,如点击.下拉等操作. 本文讲述的是通过自动化的方式登陆某一网站,其中包含Selenium+python自动化项目环境如何部 ...

  9. Selenium&Pytesseract模拟登录+验证码识别

    验证码是爬虫需要解决的问题,因为很多网站的数据是需要登录成功后才可以获取的. 验证码识别,即图片识别,很多人都有误区,觉得这是爬虫方面的知识,其实是不对的. 验证码识别涉及到的知识:人工智能,模式识别 ...

随机推荐

  1. java 散列运算浅分析 hash()

            文章部分代码图片和总结来自参考资料 哈希和常用的方法 散列,从中文字面意思就很好理解了,分散排列,我们知道数组地址空间连续,查找快,增删慢,而链表,查找慢,增删快,两者结合起来形成散列 ...

  2. nodejs常用npm包

    express常用npm包整理如下 art-template 一款js模板引擎,性能不错 jayson     一款纯node的rpc应用包,可实现rpc服务.tcp.http等服务 multer   ...

  3. redis(2)数据类型

    一.数据类型 redis的数据结构是key-value的键值对的形式,但是它和传统String-String的键值对形式不一样,它的value不仅仅是string类型,而是有着丰富的数据类型,如: 1 ...

  4. CSS3新属性注释及实例

    这里把CSS3的新属性单独拿出来讲解一下: border-radius 属性用于创建圆角 div { border:2px solid; border-radius:25px; -moz-border ...

  5. 怎么让textarea的光标靠左对齐

    1.怎么让textarea的光标靠左对齐: 把<textarea></textarea>之间空隙去掉就可以了. 2.怎么限制textarea的字数,利用maxlength属性限 ...

  6. 洛谷P1081 开车旅行(倍增)

    题意 题目链接 Sol 咕了一年的题解.. 并不算是很难,只是代码有点毒瘤 \(f[i][j]\)表示从\(i\)号节点出发走了\(2^j\)轮后总的距离 \(da[i][j]\)同理表示\(a\)的 ...

  7. Java Struts2 (一)

    一.Struts2简介 1.Struts2概述 Struts2是Apache发行的MVC开源框架.注意:它只是表现层(MVC)框架. 2.Struts2的来历 Struts1:也是apache开发的一 ...

  8. SpringBoot框架下基于Junit的单元测试

    前言 Junit是一个Java语言的单元测试框架,被开发者用于实施对应用程序的单元测试,加快程序编制速度,同时提高编码的质量.是一个在发展,现在已经到junit5,在javaEE开发中与很多框架相集成 ...

  9. visual studio code断点调试react

    在项目配置文件   .vscode\launch.json 中添加:   "sourceMaps": true,   "skipFiles": [   &quo ...

  10. webpack2-webpack.config.js配置

     写在前面: 了解更多:https://github.com/miaowwwww/webpack-learn 贴一个webpack.ocnfig.js 的配置属性表 一.代码分割: 1.插件 Comm ...