# 文章标题
title = driver.find_element(By.XPATH, '//input[@placeholder="请输入标题"]')
title.clear()
if 'title' in front_matter['title'] and front_matter['title']:
title.send_keys(front_matter['title'])
else:
title.send_keys(common_config['title'])
time.sleep(2) # 等待3秒
if summary:
summary_input = driver.find_element(By.XPATH, '//div[@class="summary"]/textarea')
summary_input.clear()
summary_input.send_keys(summary)
time.sleep(2)
设置标签
标签是一个input,这里我们也是通过xpath来定位:
if tags:
for tag in tags:
tag_input = driver.find_element(By.XPATH, '//div[@class="search-tag"]//input')
tag_input.send_keys(tag)
time.sleep(1)
tag_input.send_keys(Keys.ENTER)
在设置标签的过程中,每设置完成一个,我们就按一下回车,接下来就可以设置下一个标签了。
非常的方便。
最后的提交
最后的最后,我们就可以真正的点击提交按钮了。
if auto_publish:
publish_button = driver.find_element(By.XPATH, '//div[@class="dialog-footer-buttons"]/div[contains(text(),"确定")]')
publish_button.click()