selenium定位练习(csdn写博客)

#coding=utf-8
from selenium import webdriver
import time

driver =webdriver.Chrome()
driver.get("https://passport.csdn.net/account/login?ref=toolbar")
title = driver.title
print(title)
time.sleep(3)
driver.maximize_window()
time.sleep(2)

#登录我的CDSN
driver.find_element_by_id("username").clear()
driver.find_element_by_id("username").send_keys("xxxxxx")
driver.find_element_by_id("password").clear()
driver.find_element_by_id("password").send_keys("xxxxxx")
driver.find_element_by_class_name("logging").click()
title=driver.title
print(title)
time.sleep(5)

#写博客
driver.find_element_by_xpath("//*[@id ='showinfo']/a[5]").click() #进入到博客专栏
title=driver.title
print(title)
time.sleep(3)
driver.find_element_by_id("btn_postedit").click() #点击写博客
time.sleep(3)
driver.find_element_by_xpath("//select[@id='selType']/option[2]").click() #选择博客的类别:原创
driver.find_element_by_id("txtTitle").clear()
driver.find_element_by_id("txtTitle").send_keys("测试自动化脚本1")#输入博客标题
time.sleep(2)
driver.switch_to_frame("xhe0_iframe")
driver.find_element_by_class_name("editMode").clear()
driver.find_element_by_class_name("editMode").send_keys("试试文章长度可以多少,如果特别多的话也没有问题吗")#写博客正文
time.sleep(3)
driver.switch_to_default_content()

driver.switch_to_frame("frm_img_2")
driver.find_element_by_id("file1").send_keys(r"D:\1.jpg") #上传文件
time.sleep(2)

driver.switch_to_default_content()
driver.find_element_by_xpath("//div[@id = 'moreDiv']/div[1]/input[@id='txtTag2']").clear()
driver.find_element_by_xpath("//div[@id = 'moreDiv']/div[1]/input[@id='txtTag2']").send_keys(u"自动化") #选择类别自动化


#保存文章
driver.find_element_by_id("btnDraft").click()
text = driver.switch_to_alert()








   

你可能感兴趣的:(python,selenium,自动化)