1 #-*- coding:utf-8 -*- 2 __author__ = "carry" 3 4 from selenium import webdriver 5 import time 6 import SendKeys 7 8 profileDir = r‘C:\Users\Administrator\AppData\Roaming\Mozilla\Firefox\Profiles\odnvwnn4.default-1489915703574‘ 9 profile = webdriver.FirefoxProfile(profileDir) 10 driver = webdriver.Firefox(profile) 11 12 driver.implicitly_wait(30) 13 driver.get("http://www.cnblogs.com/lxs1314/") 14 driver.find_element_by_link_text("新随笔").click() 15 time.sleep(3) 16 17 # 点开编辑器图片 18 driver.find_element_by_css_selector("img.mceIcon").click() 19 time.sleep(3) 20 # 定位所有iframe,取第二个 21 print driver.find_elements_by_tag_name(‘iframe‘) 22 iframe = driver.find_elements_by_tag_name(‘iframe‘)[1] 23 # 切换到iframe上 24 driver.switch_to.frame(iframe) 25 # 文件路径 26 time.sleep(2) 27 driver.find_element_by_class_name("qq-upload-button").click() 28 # driver.find_element_by_name("file").click() 29 time.sleep(5) 30 # SendKeys方法输入内容 31 SendKeys.SendKeys("D:\\1.jpg") 32 time.sleep(1) 33 SendKeys.SendKeys("{ENTER}")# 发送回车键 34 time.sleep(1) 35 SendKeys.SendKeys("{ENTER}")# 因为我的电脑是搜狗输入法,所以多敲一次回车 36 #js="var q=document.getElementById(‘id‘).scrollTop=10000" 37 #js = "var q=document.documentElement.scrollTop=10000" 38 39 time.sleep(1) 40 41 driver.switch_to.default_content() 42 #将页面滚动条拖到底部 43 js="var q=document.documentElement.scrollTop=10000" 44 driver.execute_script(js) 45 time.sleep(3) 46 47 driver.find_element_by_css_selector("#Editor_Edit_lkbPost").click() 48 driver.switch_to.alert().accept() 49 driver.quit()
时间: 2024-11-07 05:32:49