以新浪微博注册页面为例,勾选单个复选框:这里以勾选 ‘新闻’ 复选框为例
?代码思想:通过定位复选框的xpth,然后点击。
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://login.sina.com.cn/signup/signup?entry=homepage") # 新浪注册页面
element = driver.find_element(By.XPATH,'//*[@id="phone-form"]/div[4]/div[2]/label[1]/input').click()
勾选全部复选框:通过每个复选框相同的属性进行定位,然后点击
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://login.sina.com.cn/signup/signup?entry=homepage")
#找到每个复选框元素相同的属性
elements = driver.find_elements(By.NAME,'hobbies[]')
for element in elements:
element.click()
|