selenium webdriver 实现百度贴吧自动签到
public static void main(String[] args) {
//TestUtils.killProcess("javaw.exe");
TestUtils.killProcess("iexplore.exe"); WebDriver driver=ExplorerBase.IESetting();
driver.manage().window().maximize();
String baseUrl= "http://www.baidu.com/";
driver.get(baseUrl);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
String name;
try {
name=driver.findElement(By.id("s_username_top")).getText();
System.out.println(name);
}catch (NoSuchElementException e) {
driver.findElement(By.id("lb")).click();
driver.findElement(By.id("TANGRAM__PSP_10__pass-pop-login-placeholder-normal")).click();
WebElement username=driver.findElement(By.id("TANGRAM__PSP_10__userName"));
username.clear();
username.sendKeys("");//username
WebElement password=driver.findElement(By.id("TANGRAM__PSP_10__password"));
password.click();
password.clear();
password.sendKeys("");//password
driver.findElement(By.id("TANGRAM__PSP_10__submit")).click();
//Assert.assertEquals("x429791240",driver.findElement(By.id("s_username_top")).getText());
}
driver.findElement(By.linkText("贴吧")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebElement element= driver.findElement(By.id("wd1"));
element.sendKeys("刘诗诗");
driver.findElement(By.id("tb_header_search_form")).submit();
String setscroll = "document.documentElement.scrollTop=100";
JavascriptExecutor jse=(JavascriptExecutor) driver;
jse.executeScript(setscroll);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
try {
WebElement elementSign= driver.findElement(By.xpath("//a[@title='签到']"));
elementSign.click();
System.out.println("亲!签到成功~");
} catch (NoSuchElementException e) {
driver.findElement(By.xpath("//a[@title='签到完成']"));
System.out.println(driver.findElement(By.xpath("//a[@title='签到完成']")).getAttribute("title"));//getText(),获得标签内文本
System.out.println("亲!今天已经签过到了~");
}
driver.quit();
}
public class Cnblogs {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer(); @Before
public void setUp() throws Exception {
driver = ExplorerBase.IESetting();
baseUrl = "http://www.cnblogs.com";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
} @Test
public void testCnblogs() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.linkText("登录")).click();
driver.findElement(By.id("tbUserName")).clear();
driver.findElement(By.id("tbUserName")).sendKeys("");
driver.findElement(By.id("tbPassword")).clear();
driver.findElement(By.id("tbPassword")).sendKeys("");
driver.findElement(By.id("btnLogin")).click();
assertEquals("苦逼IT男", driver.findElement(By.linkText("苦逼IT男")).getText());
} @After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
} private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
} private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
} private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}
public class ITeye {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer(); @Before
public void setUp() throws Exception {
driver = ExplorerBase.IESetting();
baseUrl = "http://www.iteye.com";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
} @Test
public void testITeye() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.linkText("登录")).click();
driver.findElement(By.id("user_name")).sendKeys("TestQA0");
driver.findElement(By.id("password")).sendKeys("654321a");
driver.findElement(By.id("button")).click();
assertTrue(isElementPresent(By.linkText("欢迎TestQA0")));
driver.findElement(By.linkText("退出")).click();
} @After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
} private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
} private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
} private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}
selenium webdriver 实现百度贴吧自动签到的更多相关文章
- selenium webdriver 登录百度
public class BaiduTest { private WebDriver driver; private String baseUrl; private StringBuffer veri ...
- python3之selenium.webdriver 库练习自动化谷歌浏览器打开百度自动百度关键字
import os,time,threading from selenium import webdriver from selenium.webdriver.common.keys import K ...
- 百度贴吧自动回帖的两种方式,使用requests(urllib2)和selenium两种方式回帖
本文介绍,回复贴吧指定某楼层主的帖子的方法.在这里不介绍无限发主贴和无限回复主贴的方法,无限发主题帖会爆吧,引起别人的反感,并且很容易遭到吧主的封杀:无限回主题帖,会让整个帖子的每楼的回复充满了自己的 ...
- selenium之数据驱动框架应用WPS个人中心自动签到
wps在注册后,有个每日签到的功能,签到后有几率送wps的专属金币[稻米],为了免费获得,又不想每天都是人工去执行签到动作,所以用selenium写了个小脚本,准备用数据驱动框架来完成这个事情,数据驱 ...
- selenium,webdriver模仿浏览器访问百度 基础2
学python理念 : 代码要多敲 一定要多敲 哪怕很基础 注释要清晰 由于基础1有一些注释写的很详细, 在这里有些注释没有写的很详细 可以配合基础1一起学习哦 from selenium im ...
- 【转】Selenium WebDriver + Python 环境
转自:http://www.myext.cn/webkf/a_11878.html 1. 下载必要工具及安装包 1.1 [Python开发环境] 下载并安装Python 2.7.x版本 下载地址:ht ...
- Selenium WebDriver + Python 环境配置
1. 下载必要工具及安装包 1.1.[Python开发环境] 下载并安装Python 2.7.x版本(当前支持2.x版本,不要下载最新的3.X的版本因为python3并非完全兼容python2) ...
- 转载 基于Selenium WebDriver的Web应用自动化测试
转载原地址: https://www.ibm.com/developerworks/cn/web/1306_chenlei_webdriver/ 对于 Web 应用,软件测试人员在日常的测试工作中, ...
- selenium WebDriver 八种定位方式源码
/* * 多种元素定位方式 */ package com.sfwork; import java.util.List; import org.openqa.selenium.By; import or ...
随机推荐
- vs查看动态库依赖
dumpbin是VS自带的工具,进入Visual Studio 的命令提示 查看程序或动态库所依赖的动态库 dumpbin /dependents abc.exe 查看动态库的输出函数 dumpbi ...
- Codeforces Round #622 (Div. 2)
A: 题意: 有ABC的三种菜,现在有a个A,b个B,c个C,问能组成多少种不同菜单 思路: abc都大于等于4,肯定是7种,给abc排个序,从大到小举例删减 #include<bits/std ...
- 【音乐欣赏】《JINGO JUNGLE》 - MYTH & ROID
歌名:JINGO JUNGLE 作者:MYTH & ROID [00:19.82]Don’t go away 逃げ場はない [00:27.12]Oh why? You’re crying 嗤え ...
- Linux shell cut 命令详解
详细资料请参考:博客园骏马金龙 https://www.cnblogs.com/f-ck-need-u/p/7521357.html cut命令将行按指定的分隔符分割成多列,它的弱点在于不好处理多个分 ...
- Go同步等待组/互斥锁/读写锁
1. 临界资源 package main import ( "fmt" "time" ) func main() { /* 临界资源: */ a := 1 go ...
- 每天进步一点点------DE2-70-TV例子说明
module Reset_Delay(iCLK,iRST,oRST_0,oRST_1,oRST_2); input iCLK; input iRST; output reg oRST_0; outpu ...
- UVA 12124 Assemble(二分答案)
题目链接:https://vjudge.net/problem/UVA-12124 垃圾vjudge毁我青春!! 首先这道题是解决“最小值最大”的问题,所以要二分答案. 在这里我们二分$quality ...
- JEECG弹出框提交表单
一.设备主页面(deviceMain.jsp) <t:dgToolBar title="编辑设备" icon="icon-edit" url=" ...
- 设置textarea不可拉伸
默认情况下,我们将鼠标移动到textarea的右下角时发现文本域是可以通过拖动的方式改变其大小的,这会影响我们原本的页面布局.若想设置其不可拖动,可为其添加如下属性: style="resi ...
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:component-scan'.
关于以上错误,观察是否缺少了某一项,还要注意书写的顺序 建议这一类配置文件直接复制就好了,不要自己写 <?xml version="1.0" encoding="U ...