import time
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://www.baidu.com')
driver.maximize_window()
# 隐式等待
driver.implicitly_wait(10)
time.sleep(1)
el3 = driver.find_element(By.CSS_SELECTOR,'span#s-usersetting-top') # 设置
ActionChains(driver).move_to_element(el3).perform()
time.sleep(1)
driver.find_element_by_link_text('高级搜索').click()
time.sleep(1)
checkboxs = driver.find_elements_by_name('q5') # 定位name相同的元素
for checkbox in checkboxs:
checkbox.click()
time.sleep(1)
# 单个识别,通过下标识别
time.sleep(1)
checkboxs[1].click()
time.sleep(2)
# 输入搜索内容
inputs = driver.find_elements_by_css_selector('input.c-input.adv-q-input') # css中间有空格用.代替
for i in inputs:
i.send_keys('selenium自动化测试')
time.sleep(2)
driver.close()