目录
0. 引言
随着最近疫情的爆发,各个单位可能会要求大家每天填写健康问卷以确保健康安全。这些问卷的答案都是一样的,但是需要定时填写打卡,很容易某天就忘记了。因此,我们可以用python写一个脚本,让Windows每天自动帮我们填写。
一个问卷示例:
1. 用selenium写一个自动填写表单的脚本
先上代码。
from selenium import webdriver
import selenium.webdriver.support.ui as ui
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
import selenium.webdriver.support.expected_conditions as EC
def filling():
driver = webdriver.Chrome("chromedriver.exe")
driver.get(r"https://表单链接")
# 日期
is_visible(driver, 'xpath_value1') #eg:'//*[@id="root"]/div/form/div[3]/div/div[2]/div/div[2]/div/div/span/div/div/input'
driver.find_element_by_xpath('xpath_value1').click()
is_visible(driver, 'xpath_value2')
driver.find_element_by_xpath('xpath_value2').click()
# 姓名
driver.find_element_by_xpath('xpath_value3').send_keys("你的姓名")
# 学号
driver.find_element_by_xpath('xpath_value4').send_keys("你的学号")
# 身体状况
if driver.find_element_by_xpath('xpath_value5').is_selected():
pass
else:
driver.find_element_by_xpath('xpath_value5').click()
# 位置
is_visible(driver, 'xpath_value6')
driver.find_element_by_xpath(