import time
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://pythonav.com/login/')
# id定位:
driver.find_element_by_id('su')
driver.find_elements_by_id()
# class定位:
driver.find_element_by_class_name('xxx')
driver.find_elements_by_class_name('xxx')
# xpath定位:
driver.find_element_by_xpath('xxx')
driver.find_elements_by_xpath('xxxx')
# css定位:
driver.find_element_by_css_selector('xx')
driver.find_elements_by_css_selector('xx')
# 标签定位:
driver.find_element_by_tag_name('div')
driver.find_elements_by_tag_name('div')
# a标签的link属性
driver.find_element_by_link_text('xxx')
driver.find_elements_by_link_text('xxx')
# a标签的link模糊属性
driver.find_element_by_partial_link_text('xx')
driver.find_elements_by_partial_link_text('xxx')
# 根据name定位:
driver.find_element_by_name('xx')
driver.find_elements_by_name('xx')
# css定位:
driver.find_element_by_css_selector('#id_username').send_keys('xxx')
# 浏览 f12 选中标签,鼠标右键 copy -- copy selector
# 获取span的外部nav标签
# nav = browser.find_element_by_tag_name(name='nav')
# 然后再获取nav内部的所有span标签
# span_list = nav.find_elements_by_tag_name(name='li')
# 循环绑定事件并点击:
for i in span_list:
i.click()
time.sleep(3)
time.sleep(3)
browser.quit()
'''
只能适用于超链接
link_text 精确定位
partial_link_text : 模糊定位,谨慎使用
'''
# xpath定位定输入值:
driver.find_element_by_xpath('//*[@id="id_code"]').send_keys('xxxxxxxx')