Selnium Chrome WebDriver API使用
使用
1.带参数使用
> selenium.webdriver.chrome.webdriver.WebDriver(executable_path='chromedriver',port=0, chrome_options=None, service_args=None,desired_capabilities=None, service_log_path=None)
2.不带参数使用:
> selenium.webdriver.remote.webdriver.WebDriver
使用ChromeDriver控制Chrome 浏览器
ChromeDriver下载
基本操作
使用Chrome选项配置
> create_options()
使用Chrome网络配置 返回 dict.
> get_network_conditions()
{‘latency’: 4, ‘download_throughput’: 2, ‘upload_throughput’: 2,
‘offline’: False}
指定 id.启动 Chrome
launch_app(id)
关闭Chrome browser 和ChromeDriver
quit()
设置网络参数
driver.set_network_conditions(offline=False, latency=5, # additional latency (ms) download_throughput=500 * 1024, # maximal throughput upload_throughput=500 * 1024) # maximal throughput
注意: ‘throughput’ 可以设置上传和下载
The WebDriver implementation.
使用WebDriver协议向远程服务器发送命令控制浏览器 参考
selenium.webdriver.remote.webdriver.WebDriver(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=None, browser_profile=None, proxy=None, keep_alive=False, file_detector=None)
基本:object
发送命令控制服务器 参考
属性
- command_executor - 执行命令
- error_handler - 处理错误
加入cookie参数:cookie_dict
dict对象包含key,value,可选项“path”, “domain”, “secure”, “expiry”
driver.add_cookie({
‘name’ : ‘foo’, ‘value’ : ‘bar’