美文网首页selenium + python专题我爱编程
selenium webdriver基于Python系列文章之定

selenium webdriver基于Python系列文章之定

作者: 七月尾巴_葵花 | 来源:发表于2017-03-20 13:38 被阅读54次

from selenium import webdriver

import time

import os

# 数据初始化

browser = webdriver.Chrome()

# 绝对路径

file_path = os.path.dirname(__file__) + '/html/' + 'xxxxx.html'   #本地的一个页面

print os.path.dirname(__file__)

print file_path

# 打开浏览器

browser.get(file_path)

browser.maximize_window()

# 选择页面上所有的input,然后从中过滤出所有的checkbox并勾选之

inputs = browser.find_elements_by_tag_name('input')

for input_ in inputs:

if input_.get_attribute('type') == 'checkbox':

input_.click()

time.sleep(2)

# 断言

no = 1

try:

for input_ in inputs:

if input_.get_attribute('type') == 'checkbox':

assert input_.is_selected()

print "第%s个测试ok" % no

no += 1

finally:

# 关闭浏览器

browser.quit()

相关文章

网友评论

    本文标题:selenium webdriver基于Python系列文章之定

    本文链接:https://www.haomeiwen.com/subject/hsnbnttx.html