Tuesday, 18 July 2023

Handle Add Extension Alert from webstore using only Selenium to make it work in headless

I know many will consider this a duplicate, but all the solutions use pyautogui or some other method to click on the add extension alert. Or some will say to download and load the extension using ChromeOptions. Well I do not want any of these. The reason is I need to make it work in headless mode and I can not download the extension for some reason. Here is a link to similar Question.

Python Selenium How to handle chrome store alert?

I have tried the steps in this post but they do not work The code snippet to work with is

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()

I will award a bounty of 100 reputation, if any one gives a good solution to this. Thanks in advance for any help.



from Handle Add Extension Alert from webstore using only Selenium to make it work in headless

No comments:

Post a Comment