find_element_by_id 根据id找节点
find_element_by_tagname 根据name找节点
find_elements_by_xpath 根据xpath找
find_elements_by_class_name 根据标签名找
find_elements_by_css_selector 根据class名字找
find_elements_by_link_text 根据链接的内容找
话不多说源码奉上
from selenium import webdriver
import time
#模拟浏览器对象,如果对象去操作浏览器
path = r'D:\爬虫\selenium\chromedriver.exe';
browser = webdriver.Chrome(executable_path = path)
#print(browser)
url = 'https://www.baidu.com/'
browser.get(url)
#查找input输入框
my_input = browser.find_element_by_id('kw')
#往里面写文字
my_input.send_keys('美女图片')
#点击搜索
#方法一:my_input.send_keys(Keys.TENTER)
#方法二:找到搜索按钮
button = browser.find_elements_by_tag_name('bg s_btn')
time.sleep(3)
img = browser.find_elements_by_class_name('op-img-address-link-imgs')[0]
img.click()
time.sleep(3)
browser.quit()