Selenium 入門到精通系列html
PS:Checkbox方法python
HTML:web
<html>
<head>
<title>測試頁面</title>
</head>
<body>
<form action="" method="get">您喜歡的水果?<br /><br />
<label><input name="Fruit" type="checkbox" value="" />蘋果 </label>
<label><input name="Fruit" type="checkbox" value="" />桃子 </label>
<label><input name="Fruit" type="checkbox" value="" />香蕉 </label>
<label><input name="Fruit" type="checkbox" value="" />梨 </label>
</form>
</body>
</html>
代碼:測試
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2019-04-23 16:12:33
# @Author : BenLam
# @Link : https://www.cnblogs.com/BenLam/
from selenium import webdriver
driver=webdriver.Firefox()
driver.get('test.html')
#選中全部的tag name爲input的元素
inputs=driver.find_elements_by_tag_name('input')
#for循環勾選
for i in inputs:
if i.get_attribute('type')=='checkbox':
i.click()
driver.quit()