标签:实例 sel find div text class bdr webdriver --
百度搜索框,通过.send_keys()方法
#定位百度搜索框
driver.find_element_by_id("kw").send_keys("python")
time.sleep(3)
driver.find_element_by_id("su").click()
博客园评论区,通过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)
#执行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()
标签:实例 sel find div text class bdr webdriver --
原文地址:https://www.cnblogs.com/simran/p/9266737.html