送出的需求
寫一隻python使用selenium 4.x版 搭配 chromdrivermanager 操作Chrome
打開 Gmail網站 輸入帳號密碼 進行登入
chatGPT回覆
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
# 創建 Chrome 瀏覽器設定
chrome_options = webdriver.ChromeOptions()
# 避免彈出視窗影響自動操作
chrome_options.add_argument('--disable-popup-blocking')
# 使用 ChromeDriverManager 來自動下載並管理 Chrome 驅動程式的版本
driver = webdriver.Chrome(executable_path=ChromeDriverManager().install(), options=chrome_options)
# 前往 Gmail 網站
driver.get("https://mail.google.com")
# 找到帳號輸入框,輸入帳號
email_input = driver.find_element(By.NAME, 'identifier')
email_input.send_keys('你的Gmail帳號')
# 按下「下一步」按鈕
next_button = driver.find_element(By.ID, 'identifierNext')
next_button.click()
# 等待載入,找到密碼輸入框,輸入密碼
password_input = driver.find_element(By.NAME, 'password')
password_input.send_keys('你的Gmail密碼')
# 按下「下一步」按鈕
password_next_button = driver.find_element(By.ID, 'passwordNext')
password_next_button.click()
# 等待登入完成
driver.implicitly_wait(10)
# 在這裡可以加入一些後續操作,例如讀取郵件、發送郵件等
# 關閉瀏覽器
driver.quit()
—
有意思的問題出現了
selenium + webdriver-manager
在 selenium 3.x 和 4.x 版上有很大的不同
而且我在提問的部份,已經有指定要用 4.x版
但是回覆出來的程式碼,仍是3.x的
4.x 是以Service的方式進行操作的
詳細的內容我是參考這篇
這篇的內容對於常見瀏覽器的操作方式都有說明
Chrome,Chromium,Brave,Edge,Opera(以上皆為 chrome like),Firefox,IE
當然,程式還沒有弄好,對於webdriver的物件操作不太熟
目前只能做到打開網站,另外,打開網站後會閃退,也找到解法
不過我想我對於CSS還是有一定的熟悉度
上手應該不會太久
隨機文章
- 開心神農 facebook 開心農場外掛 2.0 (2010-01-05)
- 對~再不送醫~國文程度就會低落 (2009-03-11)
- Oracle VirtualBox 上黑群 DSM 6.1.7 (2019-01-01)
- 20120628 今天的yahoo怎麼了?一堆亂碼 (2012-06-28)
- OPNsense 每日重新開機 設定 (2018-12-12)





![[chatGPT 測試] DSM 7 有什麼特色](https://chihping.aflypen.com/wp-content/uploads/2023/03/usb-ga13f61ece_1280-300x221.jpg)



