很久没有写了,现在正式入职,准备好好干,加油!

我的第一个较正式的测试代码:

from selenium import webdriver
import unittest
import sys
import importlib
import time
importlib.reload(sys)
#sys.setdefaultencoding('utf8')  python3不需要
class TestLogin(unittest.TestCase):
# 指定浏览器
def setUp(self):
self.driver = webdriver.Chrome()
# 打开url
self.driver.get("http://www.ibdata.cn/#/login") # 登录操作
def test_login(self):
username = "1111111"
password = "111111"
# 执行登录操作
#用户名的定位
self.driver.find_element_by_name("handle").clear()
self.driver.find_element_by_name("handle").send_keys(username)
time.sleep(2)
#密码的定位
#因为所有元素的条件相同所以我在此选择xpath进行定位
self.driver.find_elements_by_xpath("//input[@name='handle']")[-1].click()
self.driver.find_elements_by_xpath("//input[@name='handle']")[-1].send_keys(password) # self.driver.find_element_by_name("handle").clear()
#self.driver.find_element_by_name("handle").send_keys(password) # 点击登录
self.driver.find_element_by_class_name("sign-button").click()
time.sleep(5) # 关闭浏览器
'''def tearDown(self):
self.driver.quit()''' if __name__ == "__main__":
unittest.main()

利用python+selenium在pycharm下进行页面登陆的半自动测试的更多相关文章

  1. 利用 Python + Selenium 实现对页面的指定元素截图(可截长图元素)

    对WebElement截图 WebDriver.Chrome自带的方法只能对当前窗口截屏,且不能指定特定元素.若是需要截取特定元素或是窗口超过了一屏,就只能另辟蹊径了. WebDriver.Phant ...

  2. 使用Selenium慢慢向下滚动页面

    我正试图从航班搜索页面抓取一些数据. 此页面以这种方式工作: 你填写一个表格,然后你点击按钮搜索 – 这没关系.当您单击该按钮时,您将被重定向到包含结果的页面,这就是问题所在.这个页面连续添加结果,例 ...

  3. python+selenium+unnitest写一个完整的登陆的验证

    import unittest from selenium import webdriver from time import sleep class lonInTest (unittest.Test ...

  4. 在CentOS下利用Python+selenium获取腾讯首页的今日话题。

    1.安装依赖包 yum install wget firefox gcc zlib zlib-devel Xvfb 2.安装setuptools 官网地址:https://pypi.python.or ...

  5. Python+Selenium使用Page Object实现页面自动化测试

    Page Object模式是Selenium中的一种测试设计模式,主要是将每一个页面设计为一个Class,其中包含页面中需要测试的元素(按钮,输入框,标题 等),这样在Selenium测试页面中可以通 ...

  6. python+selenium+Firefox+pycharm版本匹配

    window(2018-05-29)最新 python:3.6.1    地址https://www.python.org/downloads/release/python-361/ selenium ...

  7. Python selenium webdriver设置js操作页面滚动条

    js2 = "window.scrollTo(0,0);" #括号中为坐标 当不知道需要的滚动的坐标大小时: weizhi2 = driver.find_element_by_id ...

  8. Python selenium webdriver设置加载页面超时

    1.  pageLoadTimeout: pageLoadTimeout方法用来设置页面完全加载的超时时间,完全加载即页面全部渲染,异步同步脚本都执行完成.没有设置超时时间默认是等待页面全部加载完成才 ...

  9. 基于Python, Selenium, Phantomjs无头浏览器访问页面

    引言: 在自动化测试以及爬虫领域,无头浏览器的应用场景非常广泛,本文将梳理其中的若干概念和思路,并基于代码示例其中的若干使用技巧. 1. 无头浏览器 通常大家在在打开网页的工具就是浏览器,通过界面上输 ...

随机推荐

  1. sql格式化并高亮

    演示地址: https://ryan-miao.github.io/sql-format-with-highlight/index.html 源码: https://github.com/Ryan-M ...

  2. 关于海康威视与Unity3d集成冲突问题解决

    一.集成 1.1 了解什么是ANSI系列与GNU系列    https://baike.baidu.com/item/ANSI%20C/7657277?fr=aladdin    https://ww ...

  3. mac 10.12 sierra 机械键盘+ratm可编程鼠标记录

      系统:mac 10.12 sierra 键盘:机械键盘 鼠标:mad catz ratm 在mac 10.11/10.12 之前: 机械键盘:一般的机械键盘在mac上使用, alt 和 win 键 ...

  4. 在chrome Sources 页 显示 Console(drawer) 页

  5. lsb_release command not found

    Linux里的lsb_release命令用来查看当前系统的发行版信 息(prints certain LSB (Linux Standard Base) and Distribution inform ...

  6. 基于jQuery扁平多颜色选项卡切换代码

    基于jQuery扁平多颜色选项卡切换代码,支持自动轮播切换,鼠标滑过切换的jQuery特效.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div class=" ...

  7. laravel框架生產vender文件夹

    方法一.修改拓展 去php.ini中查看下面三个扩展项是否开启 extension=php_fileinfo.dll extension=php_mbstring.dll extension=php_ ...

  8. 内建模块collections的使用

    # -*-coding:utf-8 -*- from collections import namedtuple Point=namedtuple('Point',['x','y']) p=Point ...

  9. Python连接Mssql

    此篇使用的是Python3.6 下载pymssql包 打开网址http://www.lfd.uci.edu/~gohlke/pythonlibs/ 用pip安装whl文件.在cmd中输入 pip in ...

  10. 为什么要用kafka、rabbit等消息队列

    1.解耦: 允许你独立的扩展或修改两边的处理过程,只要确保它们遵守同样的接口约束. 2.冗余: 消息队列把数据进行持久化直到它们已经被完全处理,通过这一方式规避了数据丢失风险.许多消息队列所采用的&q ...