selenium对富文本的操作
生活随笔
收集整理的這篇文章主要介紹了
selenium对富文本的操作
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
一、input標簽
1.input標簽是對短文本的操作。如百度首頁的輸入框<input type="text" class="s_ipt" name="wd" id="kw" maxlength="100" autocomplete="off">。值存在于value中。進入控制界面輸入命令
2.給value賦值方法:driver.find_element_by_id("kw").send_keys("baidu可是可是")
二、textarea標簽
1.以博客園評論區(qū)為例。通過js獲取value值
from selenium import webdriver import time#實例化ChromeOptions option = webdriver.ChromeOptions() #加載用戶配置 option.add_argument("--user-data-dir=C:\\Users\\devz400-08\\AppData\\Local\\Google\\Chrome\\User Data")driver = webdriver.Chrome(chrome_options=option) driver.maximize_window() driver.get("https://www.cnblogs.com/simran/p/9259467.html") time.sleep(2)#定位評論富文本框 ele_textarea = driver.find_element_by_id("tbCommentBody") #聚焦 driver.execute_script("arguments[0].focus();",ele_textarea) time.sleep(2)#執(zhí)行js語句 driver.execute_script("arguments[0].value=‘test selenium‘",ele_textarea) time.sleep(2) driver.find_element_by_id("btn_comment_submit").click() time.sleep(5)driver.quit()?
?
三、div的editor標簽
比如QQ郵箱寫郵件,因此這種也采用的是send_keys的方法,只不過這個值不在value屬性中,而是在text中
轉(zhuǎn)載于:https://www.cnblogs.com/xiaoxiaolvdou/p/9302020.html
總結(jié)
以上是生活随笔為你收集整理的selenium对富文本的操作的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Mysql中Anemometer怎么用
- 下一篇: Flash设计制作卡通风格的圣诞树步骤