chrome驱动下载:http://chromedriver.storage.googleapis.com/index.html

加载浏览器配置,需要用FirefoxProfile(profile_directory)这个类来加载,

profile_directory既为浏览器配置文件的路径地址

二、FirefoxProfile

  1. 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. 1.问题来了:Firefox的配置文件地址如何找到呢?
  2. 2.打开Firefox点右上角设置>?(帮助)>故障排除信息>显示文件夹

四、启动配置文件

  1. 1.由于文件路径存在字符:\ ,反斜杠在代码里是转义字符,这个有点代码基础的应该都知道。
  1. 2.遇到转义字符,为了不让转义,有两种处理方式:

第一种:\ (前面再加一个反斜杠)

第二种:r”\"(字符串前面加r,使用字符串原型)

  1.  
  1. from selenium import webdriver
  2. import time
  3. # 加载Firefox配置文件,可免登录
  4. profile_directory = r'C:\Users\ct-wyl\AppData\Roaming\Mozilla\Firefox\Profiles\lt6n8ynh.default'
  5. profile = webdriver.FirefoxProfile(profile_directory)
  6. webdriver = webdriver.Firefox(profile)
  7. blogurl = 'https://www.cnblogs.com'
  8. yanrublog = blogurl + r'/FlyToDream'
  9. webdriver.get(yanrublog)
  10. # 点击新随笔
  11. webdriver.find_element_by_id('blog_nav_newpost').click()
  12. time.sleep(2)
  13. edittitle = u'pythong+selenium自动创建随笔'
  14. editbody = '这里是发帖区域,赶紧写下你的思绪'
  15. webdriver.find_element_by_id('Editor_Edit_txbTitle').send_keys(edittitle)
  16. # 第一种写法:通过切换iframe
  17. # iframe = webdriver.find_element_by_id('Editor_Edit_EditorBody_ifr')
  18. # webdriver.switch_to.frame(iframe)
  19. # webdriver.find_element_by_id('tinymce').send_keys(editbody) # 富文本区输入内容
  20. # webdriver.switch_to.default_content()
  21. # 第二种,通过js编辑富文本内容
  22. js = 'document.getElementById("Editor_Edit_EditorBody_ifr").contentWindow.document.body.innerHTML="%s"'%editbody
  23. webdriver.execute_script(js)
  24. webdriver.find_element_by_id('Editor_Edit_lkbPost').click() #发布
  1.  
  1.  
  1.  

webdriver之富文本,Firefox配置加载的更多相关文章

  1. 关于flume配置加载(二)

    为什么翻flume的代码,一方面是确实遇到了问题,另一方面是想翻一下flume的源码,看看有什么收获,现在收获还谈不上,因为要继续总结.不够已经够解决问题了,而且确实有好的代码,后续会继续慢慢分享,这 ...

  2. 关于flume配置加载

    最近项目在用到flume,因此翻了下flume的代码, 启动脚本: nohup bin/flume-ng agent -n tsdbflume -c conf -f conf/配置文件.conf -D ...

  3. Java实现配置加载机制

    前言 现如今几乎大多数Java应用,例如我们耳熟能详的tomcat, struts2, netty…等等数都数不过来的软件,要满足通用性,都会提供配置文件供使用者定制功能. 甚至有一些例如Netty这 ...

  4. 异常处理之IIS配置加载出错

    问题详情:  一台部署在海外服务器,在管理IIS过程中,出现问题 There was an error when trying to connect. Do you want > to rety ...

  5. 深入理解 Laravel 中 config 配置加载原理

    Laravel的配置加载其实就是加载config目录下所有文件配置.如何过使用php artisan config:cache则会把加载的配置合并到一个配置文件中,下次请求就不会再去加载config目 ...

  6. Springboot学习01- 配置文件加载优先顺序和本地配置加载

    Springboot学习01-配置文件加载优先顺序和本地配置加载 1-项目内部配置文件加载优先顺序 spring boot 启动会扫描以下位置的application.properties或者appl ...

  7. Unity3d通用工具类之数据配置加载类-ini配置文件加载

    Unity3d通用工具类之数据配置加载类-ini配置文件加载 上次我们讲过xml文件的加载配置管理,今天我们换个配置文件,也是比较常见的配置文件.ini格式的数据. 按照国际管理先贴一张啥是.ini文 ...

  8. Unity3d通用工具类之数据配置加载类

    今天,我们来讲讲游戏中的数据配置加载. 什么是游戏数据加载呢?一般来说游戏中会有场景地图. 按照国际惯例,先贴一张游戏场景的地图: 在这张地图上,我们可以看到有很多正六边形,正六边形上有树木.岩石等. ...

  9. ASP.NET网站使用Kindeditor富文本编辑器配置步骤

    1. 下载编辑器 下载 KindEditor 最新版本,下载页面: http://www.kindsoft.net/down.php 2. 部署编辑器 解压 kindeditor-x.x.x.zip ...

随机推荐

  1. MongoDB Schema Design

    Normalization: ...... Relationships: One-to-One relationship: 1-to-many: many-to-many:

  2. js动态改变setInterval的时间

    <!DOCTYPE html> <html> <head> <!--meta name="viewport" content=" ...

  3. VUE项目注意点

    1.vue组件中img标签的src属性绑定数据: <img :src="img" alt="图片" /> //scriptdata() { img: ...

  4. Linux进程PRI与NI值

    1.PRI -> 进程的优先级,大部分系统(Linux.UCOSII)都是数字越低优先级越高,进程就优先运行 , Linux中的PRI(new) = PRI(old) + nice ,其中 , ...

  5. dom渲染方面的优化浅谈

    今天分享一个面试经验,上周面试中一位印象很深的面试官(主要长得很帅),问我了一个我至今印象很深刻的问题,当然不是什么你之后的职业规划啊,你工作中遇到过哪些问题啊之类的.原起于一道面试题,小伙伴们可以想 ...

  6. Android Glide 加载图片

    0.借鉴文章地址:http://blog.csdn.net/zivensonice/article/details/51835802 和 http://www.cnblogs.com/zhaoyanj ...

  7. oracle中 sql%rowcount 用法

    sql%rowcount用于记录修改的条数,必须放在一个更新或者删除等修改类语句后面执行,select语句用于查询的话无法使用, 当你执行多条修改语句时,按照sql%rowcount 之前执行的最后一 ...

  8. Rsync+unison双向文件同步

    1.配置RSYNC服务器的同步源: 基于SSH同步源 rsync -avz /server/rsyncd/*  chen@172.16.23.204:/client/rsyncd 基于RSYNC同步源 ...

  9. 【数据结构】算法 LinkList (Insertion Sort List 链表插入排序)

    将一个单链表进行处理后,所得结果为一有序链表 Solution: 将原始链表逐个查询,插入新链表,在插入的同时对链表进行排序.时间复杂度O(n*n) public ListNode insertion ...

  10. Jenkins连接Window服务器,上传jar并启动

    https://blog.csdn.net/achenyuan/article/details/81181347