from selenium import webdriver from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as Ec from selenium.webdriver.common.by import By from selenium.webdriver.common.action_chains import ActionChains # 鼠标操作的类 import time driver = webdriver.Chrome() driver.get("https://www.baidu.com/") driver.maximize_window() # 输入柠檬班 driver.find_element_by_xpath('//input[@id="kw"]').send_keys("柠檬班") # 点击百度一下按钮 driver.find_element_by_xpath('//input[@id="su"]').click() # 定位 腾讯课堂 这个元素 WebDriverWait(driver,20).until(Ec.presence_of_element_located((By.XPATH,'//a[contains(text(),"自动化测试视频 - 百度云网盘 - 盘搜搜")]'))) time.sleep(2) # 定位元素 ele = driver.find_element_by_xpath('//a[contains(text(),"自动化测试视频 - 百度云网盘 - 盘搜搜")]') # 滚动 #driver.execute_script('arguments[0].scrollIntoView(false);',ele) 跟浏览器底部齐平 driver.execute_script('arguments[0].scrollIntoView();',ele)