如何仅用Selenium在无头模式下处理Chrome应用商店扩展添加弹窗
无头模式下无需下载添加Chrome扩展的问题
目前Stack Overflow上的相关方案,要么是用pyautogui这类工具点击添加扩展的弹窗,要么是通过ChromeOptions下载并加载扩展,但这些都满足不了我的需求。我需要在无头模式下完成扩展添加,而且因为某些原因没法下载扩展。试过相关帖子里的方法都没用,我的代码片段如下:
import time import pyautogui from selenium.webdriver.common.by import By from selenium.webdriver.chrome.service import Service from selenium.webdriver.support.ui import WebDriverWait from webdriver_manager.chrome import ChromeDriverManager from undetected_chromedriver import Chrome, ChromeOptions from selenium.webdriver.support import expected_conditions as EC service = Service(ChromeDriverManager().install()) options = ChromeOptions() options.add_argument("--disable-web-security") options.add_argument("--disable-xss-auditor") options.add_argument("--no-sandbox") driver = Chrome(service=service, chrome_options=options) driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: function() {return false}})") wait = WebDriverWait(driver, 50) driver.get("https://chrome.google.com/webstore/detail/chatgpt-chrome-extension/gabfffndnhbbjlgmbogpfaciajcbpkdn") wait.until(EC.element_to_be_clickable((By.XPATH, '//div[contains(@class, "webstore-test-button-label") and contains(text(), "Add")]'))) driver.find_element(By.XPATH, '//div[contains(@class, "webstore-test-button-label") and contains(text(), "Add")]').click() time.sleep(5) pyautogui.hotkey('tab','enter', interval=0.1) time.sleep(5) driver.quit()
内容的提问来源于stack exchange,提问作者farhan jatt
相关产品推荐
相关产品推荐

