# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
url = "https://www.baidu.com"
driver.get(url=url)
import time
time.sleep(3)
# 這兩種都是可以的 點擊事件 一種是鍵盤點擊, 第二種 就祭出我們的execute_script 執行js, 簡單粗暴
# 輸入框,輸入csdn
driver.find_element_by_id("kw").send_keys("csdn")
time.sleep(3)
# 回車元素
driver.find_element_by_id("su").send_keys(Keys.ENTER)
time.sleep(3)
#進入csdn主頁,click點擊
driver.find_element_by_xpath("//*[@id='1']/h3/a[1][@target='_blank']").click()
# 這兩種方法都是可以的,我們這裏面沒有采用原始的方式 .click()
py點擊a元素
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.