selenium tips

简介:

【Selenium Python

1、selenium3 python github

2、文档:readthedocs版github版API。貌似后者只是前者的一个章节。


【Selenium Python WebDriver

1、设置浏览器窗口大小:WebDriver.set_window_size

2、获取cookie:WebDriver.get_cookies

3、保存当前页面:WebDriver.page_source

4、保存当前页面截图:WebDriver.save_screenshot

5、元素查找:WebDriver.find_element_by_*

6、去掉链接的新标签页打开属性(target="_blank"):

1
2
aEle  =  Driver.find_elements_by_tag_name( 'a' ):
Driver.execute_script( "arguments[0].removeAttribute('target')" , aEle)


【Selenium Python WebElement

1、文本框清空:WebElement.clear

2、文本框填写:WebElement.send_keys

3、按钮(元素)点击:WebElement.click

4、定位元素坐标:WebElement.location

5、获取元素的宽度和高度:WebElement.size

6、保存元素截图:element.screenshot


【Selenium Python Firefox

1、Firefox驱动:https://github.com/mozilla/geckodriver/releases

2、禁止firefox加载图片:Disable images in Selenium Python

3、Firefox设置代理:

1
2
3
4
5
profile  =  webdriver.FirefoxProfile()
profile.set_preference( "network.proxy.type" 1 )
profile.set_preference( "network.proxy.http" , ProxyAddr)
profile.set_preference( "network.proxy.http_port" , ProxyPort)
Driver  =  webdriver.Firefox(profile)

4、如果不在环境变量中设置驱动路径,可以用executable_path指定驱动文件路径:

1
webdriver.Firefox(executable_path = r 'E:\webdriver\geckodriver.exe' )


【Selenium Python Chrome

1、Chrome驱动:https://sites.google.com/a/chromium.org/chromedriver/home

2、禁止Chrome加载图片:Python: Disable images in Selenium Google ChromeDriverselenium设置:浏览器不显示图片

3、如果不在环境变量(Path)中设置驱动路径,可以用executable_path指定驱动文件路径:

1
webdriver.Chrome(executable_path = r 'E:\webdriver\chromedriver.exe' )

4、selenium3、chorme55下的一些配置。

1
2
3
4
5
6
7
8
chromeOptions  =  webdriver.ChromeOptions()
prefs  =  {}
#禁用图片
prefs[ 'profile.managed_default_content_settings.images' =  2
#设置下载目录
prefs[ 'download.default_directory' =  'D:/tmp'
chromeOptions.add_experimental_option( "prefs" ,prefs)
browser  =  webdriver.Chrome(chrome_options = chromeOptions)


【相关阅读】

1selenium之WebDriver

2、Python将浏览器cookies共享给requests库

3、数据抓取的艺术(一):Selenium+Phantomjs数据抓取环境配置

4、Skip image loading by selenium

5、Selenium WebDriver go to page without waiting for page load

6、Get HTML Source of WebElement in Selenium WebDriver using Python

7、How to print the contents in the “ui”,“li” tags using selenium web driver


*** walker * Updated 2016-12-2 ***

本文转自walker snapshot博客51CTO博客,原文链接http://blog.51cto.com/walkerqt/1596120如需转载请自行联系原作者

RQSLT
相关文章
|
3月前
|
Web App开发 IDE 开发工具
为什么AirtestIDE的selenium Window突然无法检索控件了?
为什么AirtestIDE的selenium Window突然无法检索控件了?
|
3月前
|
Python
Python selenium 页面滚动
Python selenium 页面滚动
14 0
|
6月前
|
前端开发 测试技术 Python
Python Selenium元素定位方法详解
Python Selenium元素定位方法详解
|
6月前
|
Web App开发 前端开发 JavaScript
Python Selenium 浏览器打印预览
Python Selenium 浏览器打印预览
|
9月前
|
前端开发 黑灰产治理 索引
selenium-元素定位+下拉框代码实战
selenium-元素定位+下拉框代码实战
115 0
|
API
selenium源码通读·6 |webdriver/common/alert.py-Alert类分析
selenium源码通读·6 |webdriver/common/alert.py-Alert类分析
80 0
selenium源码通读·6 |webdriver/common/alert.py-Alert类分析
|
缓存
selenium获取text方法
selenium获取text方法
6368 3
|
Web App开发 数据采集 开发者
Python爬虫:chrome网页解析工具-XPath Helper
Python爬虫:chrome网页解析工具-XPath Helper
187 0
|
测试技术
Python+Appium自动化测试(8)-swipe()滑动页面
app自动化测试过程中,经常会遇到滑动屏幕操作,appium框架的话我们可以使用webdriver提供的swipe()方法来对屏幕页面进行上滑、下滑、左滑、右滑操作。
Python+Appium自动化测试(8)-swipe()滑动页面