#-*-coding:utf-8-*-from selenium import webdriverfrom time import sleep #前提条件,需要提前登录账户,获取配置文件才能打开随笔的编辑页面#火狐找到配置文件路径:帮助>故障排除信息>配置文件夹>显示文件夹#应用场景,主要是做免登录操作profileDir = "C:\Users\Administrator\AppData\Roaming\Mozilla\Firefox\Profiles\yn80ouvt.default"profile = webdriver.FirefoxProfile(profileDir)driver = webdriver.Firefox(profile) url = "https://i.cnblogs.com/EditPosts.aspx?opt=1"driver.get(url) driver.find_element_by_xpath(".//*[@id=‘Editor_Edit_EditorBody_uploadImage‘]").click()driver.implicitly_wait(20) # 等待元素展示# 定位所有iframe,取第二个,取框架,然后再选择按钮输入图片文件路径frame = driver.find_elements_by_tag_name(‘iframe‘)[1]driver.switch_to.frame(frame)driver.find_element_by_name(‘file‘).send_keys(r"E:\1.png")sleep(5)driver.quit()
原文地址:https://www.cnblogs.com/tDayUp/p/8733994.html
时间: 2024-11-02 07:51:38