from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option("useAutomationExtension", False)
service = ChromeService(executable_path=CHROMEDRIVER_PATH)
driver = webdriver.Chrome(service=service, options=options)
# selenium 4.0
#id
x = driver.find_element(By.ID, 'kw') #id
#name
x = driver.find_element(By.NAME, 'wd') #id
#class
x = driver.find_element(By.CLASS_NAME, 'cos-pc') #id
#TAG p div span ul li
x = driver.find_element(By.TAG_NAME, 'body') #id
#By.LINK_TEXT表示全部匹配linktext定位找到元素
x = driver.find_element(By.LINK_TEXT, '百度首页') #id
#By.PARTIAL_LINK_TEXT表示模糊匹配linktext定位找到元素
x = driver.find_element(By.PARTIAL_LINK_TEXT, '百度首页')
x = driver.execute_script(js)
selenium 4.0
最新推荐文章于 2024-09-03 16:24:51 发布