Selenium + Python 基础学习
Part 1. Selenium + Python 基础学习
- - - -学习平台:https://www.bilibili.com/video/BV1d4411H7hs?p=3
1、关于下载与安装
借鉴:http://www.51testing.com/html/43/n-4464743.html,使用python+Chrome+selenium进行学习
2、Today's Selenium Learning
1.使用python shell,用webdriver对浏览器操作
先用windows+r 打开dos命令窗口,输入python,再导入webdriver的模块:from selenium import webdriver
1)b = webdriver.Chrome() #打开浏览器
help(b.get)#使用b的方法帮助
2)b.get('http://www.baidu.com') #打开一个网页
url,title/找元素的方式
判断访问是否有效, 判断是否打开正确的百度页面:
b.title #通过标题判断,正确时返回'百度一下,你就知道'
'百度' in b.title #通过标题判断,正确时返回true
b.current_url #通过判断当前的url
3)元素定位
ele =find_element_by_...
元素名称 webdriver API
id find_element_by_id()
name find_element_by_name()
class name find_element_by_class_name()
tag name find_element_by_tag_name()
link text find_element_by_link_text()
partial link text find_element_by_partial_link_text()
xpath find_element_by_xpath()
css selector find_element_by_css_selector()
4)查看元素是否正确
id ele
type ele
ele.id
ele.size
5)元素操作方式:
ele.方法
clear() #清空元素内容
send_keys('arg') #模拟按键输入
click() #点击
submit #提交表单
b.back() #back 退回

浙公网安备 33010602011771号