from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
from selenium.webdriver.chrome.options import Options import time
import selenium
import random # from selenium.webdriver.common.desired_capabilities import DesiredCapabilities def driver_open():
# dcap = dict(DesiredCapabilities.PHANTOMJS)
# dcap["phantomjs.page.settings.userAgent"] = (r"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3100.0 Safari/537.36")
options = Options()
options.add_argument('--log-level=3')
driver = webdriver.Chrome(executable_path='E:\chromedriver\chromedriver.exe', chrome_options=options)
return driver def next_windows(driver,current_window):
window_handles = driver.window_handles
for window_handle in window_handles:
if current_window != window_handle:
handleb = window_handle driver.switch_to.window(handleb)
return driver def next_windows_handle(driver,current_window):
window_handles = driver.window_handles
for window_handle in window_handles:
if current_window != window_handle:
handleb = window_handle
return handleb if __name__ == '__main__':
learn_dict = {}
driver = driver_open()
driver.maximize_window()
driver.implicitly_wait(10) # seconds
# # Theoretical study
theoretical_study_url = 'xxxxx'
driver.get(theoretical_study_url)
time.sleep(20)
current_window = driver.current_window_handle
print(current_window)
# 浏览6篇文章
article = 6
elements = driver.find_elements_by_xpath('//span[contains(@class,"text")]')
for element in elements:
element.click()
driver = next_windows(driver,current_window)
client_height = driver.execute_script("return document.body.clientHeight;")
# scroll_height = driver.execute_script("return document.body.scrollWidth;") # print(scroll_height)
init_position = 0
while (client_height > init_position):
init_position = init_position + 200
js_string = "window.scrollTo(0," + str(init_position) + ");"
driver.execute_script(js_string)
sleep_time = random.randint(2, 4)
time.sleep(sleep_time) time.sleep(3)
driver.close()
driver.switch_to.window(current_window)
article = article - 1
if(article == 0):
break driver.get('xxxxxx')
time.sleep(3) window_handles = driver.window_handles
for window_handle in window_handles:
current_window = window_handle driver.switch_to.window(current_window)
# 浏览6个视频
videos_count = 6
videos = driver.find_elements_by_xpath('//div[contains(@class,"innerPic")]')
for video in videos:
driver.switch_to.window(current_window)
video.click()
driver = next_windows(driver, current_window)
js_string = "window.scrollTo(0,400);"
driver.execute_script(js_string)
time_sleep = random.randint(10,50)
time.sleep(time_sleep)
driver.close()
videos_count = videos_count - 1
if(videos_count == 0):
break driver.quit()

  

【自动化测试】WebDriver使用的更多相关文章

  1. 《手把手教你》系列技巧篇(二十三)-java+ selenium自动化测试-webdriver处理浏览器多窗口切换下卷(详细教程)

    1.简介 上一篇讲解和分享了如何获取浏览器窗口的句柄,那么今天这一篇就是讲解获取后我们要做什么,就是利用获取的句柄进行浏览器窗口的切换来分别定位不同页面中的元素进行操作. 2.为什么要切换窗口? Se ...

  2. 编写unit test以及自动化测试WebDriver

    http://msdn.microsoft.com/en-us/library/hh694602.aspx#BKMK_Quick_starts   http://www.seleniumhq.org/ ...

  3. Selenium自动化测试WebDriver下载

    1. 所有版本chrome下载 是不是很难找到老版本的chrome?博主收集了几个下载chrome老版本的网站,其中哪个下载的是原版的就不得而知了. http://www.slimjet.com/ch ...

  4. Selenium (4) —— Selenium是什么? WebDriver是什么?做什么?(101 Tutorial)

    Selenium (4) -- Selenium是什么? WebDriver是什么?做什么?(101 Tutorial) selenium版本: v2.48.0 (Standalone Seleniu ...

  5. Web前端工程师成长之路——知识汇总

    一.何为Web前端工程师?          前端工程师,也叫Web前端开发工程师.他是随着web发展,细分出来的行业.Web前端开发工程师,主要职责是利用(X)HTML/CSS/JavaScript ...

  6. Web前端工程师成长之路

    一.何为Web前端工程师?        前端工程师,也叫Web前端开发工程师.他是随着web发展,细分出来的行业.Web前端开发工程师,主要职责是利用(X)HTML/CSS/JavaScript/D ...

  7. 如何成为一名优秀的前端工程师 (share)

    发现一篇不错的博文,和大家分享一下,为有志成为一名优秀前端工程师的童鞋们提供一个参考. :)~ 本文来源:http://www.biaodianfu.com/what-makes-a-good-fro ...

  8. Web前端知识技能大汇总

    项目起源 还记得@jayli 的这幅前端知识结构图么. 图片的形式具有诸多的不便.缺失源图的我们,无法为此图贡献些什么,随着时间的迁移,或许有些技术点会发生改变,所以有了这个GitHub项目.我们可以 ...

  9. 前端技能汇总 Frontend Knowledge Structure

    Frontend Knowledge Structure 项目起源 还记得@jayli 的这幅前端知识结构图么. 图片的形式具有诸多的不便.缺失源图的我们,无法为此图贡献些什么,随着时间的迁移,或许有 ...

  10. Web 建站技术中,HTML、HTML5、XHTML、CSS、SQL、JavaScript、PHP、ASP.NET、Web Services 是什么(转)

    Web 建站技术中,HTML.HTML5.XHTML.CSS.SQL.JavaScript.PHP.ASP.NET.Web Services 是什么?修改 建站有很多技术,如 HTML.HTML5.X ...

随机推荐

  1. [Git] 006 在本地新建一个仓库

    1. 方法一 1.1 思路 在 GitHub 上新建一个仓库 clone 到本地 1.2 行动 1.2.1 在 GitHub 上选好自己已有的仓库 点击 "Clone or download ...

  2. Centos 7下Hadoop分布式集群搭建

    一.关闭防火墙(直接用root用户) #关闭防火墙 sudo systemctl stop firewalld.service #关闭开机启动 sudo systemctl disable firew ...

  3. 剑指Offer编程题(Java实现)——替换空格

    题目描述 请实现一个函数,将一个字符串中的每个空格替换成“%20”.例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. 解题思路1 在字符串尾部填充任 ...

  4. 简单实现一个textarea自适应高度

    textarea自适应的实现方法很多,原理其实比较简单:监听textarea的input或者键盘事件,获取元素的scrollHeight,重置textarea元素的高度. 预览地址:textarea ...

  5. Connection keepalive

    TCP    keepalive = 心跳包 linux  tcp keepalive 参数: tcp_keepalive_time:       7200 tcp_keepalive_intvl  ...

  6. WannaCry的UWP版,哈哈哈

  7. 在eclipse里搜索maven项目需要的dependency

    eclipse直接就可以通过下载同步仓库索引,直接关键字查询需要的dependency. 前提是你已经在你的eclipse上配好了maven正确的环境. 1. 设置在开启eclipse时下载同步仓库索 ...

  8. #1062 - Duplicate entry '0' for key 'PRIMARY'—— mysql的小问题

    问题:# 1062 -重复输入“0”. 原因:我估计可能是数据表中主键这一栏已经有一个为“0”了,一般出现这种问题是以int类型的字段在输入时没有输如数据,而int类型默认值为“0”,而你之前第一条数 ...

  9. 【记录】@Transactional

    参考链接:https://blog.csdn.net/nextyu/article/details/78669997 参考链接:https://www.xuebuyuan.com/3222458.ht ...

  10. 2018-8-10-使用-Resharper-特性

    title author date CreateTime categories 使用 Resharper 特性 lindexi 2018-08-10 19:16:51 +0800 2018-4-25 ...