webdriver之富文本,Firefox配置加载
chrome驱动下载:http://chromedriver.storage.googleapis.com/index.html
加载浏览器配置,需要用FirefoxProfile(profile_directory)这个类来加载,
profile_directory既为浏览器配置文件的路径地址
二、FirefoxProfile
1.要想了解selenium里面API的用法,最好先看下相关的帮助文档打开cmd窗口,
输入如下信息:
-》python
-》from selenium import webdriver
-》help(webdriver.FirefoxProfile)
Help on class FirefoxProfile in module
selenium.webdriver.firefox.firefox_profile:
class FirefoxProfile(builtin.object)
| Methods defined here:
|
| init(self, profile_directory=None)
| Initialises a new instance of a Firefox Profile
|
| :args:
| - profile_directory: Directory of profile that you want to use.
| This defaults to None and will create a new
| directory when object is created.
2.翻译过来大概意思是说,这里需要profile_directory这个配置文件路径的参数
3.profile_directory=None,如果没有路径,默认为None,启动的是一个新的,
有的话就加载指定的路径。
三、profile_directory
1.问题来了:Firefox的配置文件地址如何找到呢?
2.打开Firefox点右上角设置>?(帮助)>故障排除信息>显示文件夹
四、启动配置文件
1.由于文件路径存在字符:\ ,反斜杠在代码里是转义字符,这个有点代码基础的应该都知道。
2.遇到转义字符,为了不让转义,有两种处理方式:
第一种:\ (前面再加一个反斜杠)
第二种:r”\"(字符串前面加r,使用字符串原型)
from selenium import webdriver
import time
# 加载Firefox配置文件,可免登录
profile_directory = r'C:\Users\ct-wyl\AppData\Roaming\Mozilla\Firefox\Profiles\lt6n8ynh.default'
profile = webdriver.FirefoxProfile(profile_directory)
webdriver = webdriver.Firefox(profile)
blogurl = 'https://www.cnblogs.com'
yanrublog = blogurl + r'/FlyToDream'
webdriver.get(yanrublog)
# 点击新随笔
webdriver.find_element_by_id('blog_nav_newpost').click()
time.sleep(2)
edittitle = u'pythong+selenium自动创建随笔'
editbody = '这里是发帖区域,赶紧写下你的思绪'
webdriver.find_element_by_id('Editor_Edit_txbTitle').send_keys(edittitle)
# 第一种写法:通过切换iframe
# iframe = webdriver.find_element_by_id('Editor_Edit_EditorBody_ifr')
# webdriver.switch_to.frame(iframe)
# webdriver.find_element_by_id('tinymce').send_keys(editbody) # 富文本区输入内容
# webdriver.switch_to.default_content()
# 第二种,通过js编辑富文本内容
js = 'document.getElementById("Editor_Edit_EditorBody_ifr").contentWindow.document.body.innerHTML="%s"'%editbody
webdriver.execute_script(js)
webdriver.find_element_by_id('Editor_Edit_lkbPost').click() #发布
最新文章
- 如何理解vue.js组件的作用域是独立的
- 破解加密PDF文件pdfcrack
- 【ASP.NET 进阶】获取MP3文件信息并显示专辑图片
- mysql复制的配置
- 【linux】
- iOS开发中GCD在多线程方面的理解
- 标头“Vary:Accept-Encoding”指定方法及其重要性分析
- 基于Qt的图像采集系统
- SqlServer创建数据表描述及列描述信息
- 运行期以索引获取tuple元素-C++14
- CORS:source,princple,implimentation in Spring
- HISI VENC 实际输出帧率控制
- java 通过域名获取ip
- 王之泰201771010131《面向对象程序设计(java)》第六周学习总结
- netty2 案例:数据通信
- Python数据结构——栈的列表实现
- c++并行计算库TBB和PPL的基本用法
- Mysql安装(绿色版安装)
- centos 7 部署k8s集群
- CSS文档流、块级元素、内联元素
热门文章
- mysql中的concat,concat_ws(),group_concat()
- zipkin链路追踪
- btcpool之GbtMaker
- 怎么eclipse或MyEclipse中添加javaSe的源码
- 【HBase】-NO.140.HBase.1 -【HBase】
- LeetCode 15 输入无序、有重复,输出排重版 3-Sum
- table的thead,tbody,tfoot
- 关于.net后台的异步刷新的问题
- python虚拟环境迁移
- 用php实现表格