from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.common.action_chains import ActionChains
# 创建 WebDriver 对象,指明使用chrome浏览器驱动
wd = webdriver.Chrome(r'C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe')
# 调用WebDriver 对象的get方法 可以让浏览器打开指定网址
wd.get('https://passport.csdn.net/')
elements = wd.find_element(By.XPATH, "/html/body/div[2]/div/div[2]/div/div[1]/div[1]/div[1]/span[2]")
elements.click()
element = wd.find_element(By.CLASS_NAME, 'base-input-text')# 根据id选择元素,返回的就是该元素对应的WebElement对象
# 通过该 WebElement对象,就可以对页面元素进行操作了
# 比如输入字符串到 这个 输入框里
element.send_keys('Selenium_username')
element = wd.find_element(By.XPATH, "/html/body/div[2]/div/div[2]/div/div[1]/div[1]/div[2]/div/div[2]/div/input")
element.send_keys('Selenium_pw')
element = wd.fi
Selenium定位CSDN登录页面元素
于 2021-10-31 18:14:16 首次发布