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 实现百度贴吧自动签到的更多相关文章

  1. selenium webdriver 登录百度

    public class BaiduTest { private WebDriver driver; private String baseUrl; private StringBuffer veri ...

  2. python3之selenium.webdriver 库练习自动化谷歌浏览器打开百度自动百度关键字

    import os,time,threading from selenium import webdriver from selenium.webdriver.common.keys import K ...

  3. 百度贴吧自动回帖的两种方式,使用requests(urllib2)和selenium两种方式回帖

    本文介绍,回复贴吧指定某楼层主的帖子的方法.在这里不介绍无限发主贴和无限回复主贴的方法,无限发主题帖会爆吧,引起别人的反感,并且很容易遭到吧主的封杀:无限回主题帖,会让整个帖子的每楼的回复充满了自己的 ...

  4. selenium之数据驱动框架应用WPS个人中心自动签到

    wps在注册后,有个每日签到的功能,签到后有几率送wps的专属金币[稻米],为了免费获得,又不想每天都是人工去执行签到动作,所以用selenium写了个小脚本,准备用数据驱动框架来完成这个事情,数据驱 ...

  5. selenium,webdriver模仿浏览器访问百度 基础2

    学python理念  :  代码要多敲 一定要多敲 哪怕很基础  注释要清晰 由于基础1有一些注释写的很详细, 在这里有些注释没有写的很详细 可以配合基础1一起学习哦 from selenium im ...

  6. 【转】Selenium WebDriver + Python 环境

    转自:http://www.myext.cn/webkf/a_11878.html 1. 下载必要工具及安装包 1.1 [Python开发环境] 下载并安装Python 2.7.x版本 下载地址:ht ...

  7. Selenium WebDriver + Python 环境配置

    1.   下载必要工具及安装包 1.1.[Python开发环境] 下载并安装Python 2.7.x版本(当前支持2.x版本,不要下载最新的3.X的版本因为python3并非完全兼容python2) ...

  8. 转载 基于Selenium WebDriver的Web应用自动化测试

    转载原地址:  https://www.ibm.com/developerworks/cn/web/1306_chenlei_webdriver/ 对于 Web 应用,软件测试人员在日常的测试工作中, ...

  9. selenium WebDriver 八种定位方式源码

    /* * 多种元素定位方式 */ package com.sfwork; import java.util.List; import org.openqa.selenium.By; import or ...

随机推荐

  1. go基础_接口断言

    // interface package main import ( "fmt" ) //定义一个接口,接口名字Inter,接口的方法集有2个方法 type Inter inter ...

  2. C语言对两个浮点数进行比较的方法

    C语言对两个浮点数进行比较: C语言用"=="来比较两个浮点数,返回值完全是不确定的.  因此只能定义一个精度来确定是否相等: if(fabs(a-b) < 0.000000 ...

  3. Uva 136 丑数

    n^2暴力就完事,但是上限要高,不然就算不到对应的1500,刘汝佳的写法更好. #include <bits/stdc++.h> using namespace std; const in ...

  4. 【题解】Rusty String [CF827E]

    [题解]Rusty String [CF827E] 传送门:\(\text{Rusty String}\) \(\text{[CF827E]}\) [题目描述] 多组数据,每组数据给出一个由 \(V, ...

  5. 3、高级方法(Advanced Recipes)

    学习目录:树莓派学习之路-GPIO Zero 官网地址:https://gpiozero.readthedocs.io/en/stable/recipes_advanced.html 环境:Ubunt ...

  6. Codeforces Round #622 (Div. 2) A. Fast Food Restaurant

    Tired of boring office work, Denis decided to open a fast food restaurant. On the first day he made ...

  7. js正则验证表达式验证

    /* 合法uri */ export function validateURL(textval) {  const urlregex = /^(?:http(s)?:\/\/)?[\w.-]+(?:\ ...

  8. python学习之网路操作

    socket:服务器与客户端的常规操作,但默认创建的的sever.socket是阻塞式,不支持多个客户端的连接,要想连接多个客户端需要引入多线程.但对于IO类型来说大部分时间其实都在IO上与创建多个线 ...

  9. Python - 关于属性访问的优先级,属性访问顺序,python attributel lookup,类和实例访问属性的顺序

    object.__getattribute__(self, name) 类中的数据描述符 object.__dict__.get(name) 自身属性字典 object.__class__.__dic ...

  10. Django框架中的Cookie和Session

    学习内容: (1)cookie (2)session Web是基于请求/响应模式,HTTP协议是无状态的,但是基于 Internet的各种服务系统应运而生,建立商业站点或者功能比较完善的个人站点,常常 ...