学习了几种定位方式--记录

from selenium import webdriver

from time import sleep

from selenium.webdriver.common.by import By
# 通过ID来定位
# driver = webdriver.Chrome()
# driver.maximize_window()
# driver.get('http://www.baidu.com')
# sleep(3)
# driver.find_element(By.ID, 'kw').send_keys("极客时间")
# driver.find_element(By.ID, "su").click()
#
# sleep(3)
# driver.quit()


# 通过NAME来定位
# driver = webdriver.Chrome()
# driver.maximize_window()
# driver.get('http://www.baidu.com')
# sleep(3)
# driver.find_element(By.NAME, 'wd').send_keys("极客时间")
# driver.find_element(By.ID, 'su').click()
#
# sleep(3)
# driver.quit()

# # 通过xpath来定位
# driver = webdriver.Chrome()
# driver.maximize_window()
# driver.get('http://www.baidu.com')
# sleep(1)
# driver.find_element(By.XPATH, '//*[@id="kw"]').send_keys("极客时间")
# driver.find_element(By.ID, 'su').click()
#
# sleep(3)
# driver.quit()

# 通过CSS选择器来定位
# driver = webdriver.Chrome()
# driver.maximize_window()
# driver.get('http://www.baidu.com')
# sleep(1)
# driver.find_element(By.CSS_SELECTOR, '#kw').send_keys("极客时间")
# driver.find_element(By.ID, 'su').click()
#
# sleep(3)
# driver.quit()

posted @ 2023-08-13 16:34  生命不止追求不断  阅读(7)  评论(0编辑  收藏  举报