#!/usr/bin/env python
# -*- coding:utf-8 -*-
from selenium import webdriver
import time
options = webdriver.ChromeOptions()
prefs = {
'profile.default_content_setting_values':
{
'notifications': 2
}
}
options.add_experimental_option('prefs', prefs) # 关掉浏览器左上角的通知提示
options.add_argument("disable-infobars") # 关闭'chrome正受到自动测试软件的控制'提示
driver = webdriver.Chrome(chrome_options=options)
driver.maximize_window()
driver.implicitly_wait(10)
driver.get("http://www.baidu.com")
try:
s_input = driver.find_element_by_id("kw") #通过ID查找元素
s_input.send_keys("酷酷木女侠")
s_enter = driver.find_element_by_id("su")
s_enter.click()
print("查找元素成功")
except Exception as e:
print("出现问题了:" + format(e))
time.sleep(5)
driver.quit()
python+selenium小结1:通过元素id查找元素
最新推荐文章于 2024-09-14 17:37:59 发布