Trying to handle chrome extension through selenium but i dont know how to handle the popup after clicking download(shown below)
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from os import system
import time
import subprocess
address = r'C:\Program Files\Google\Chrome Beta\Application\chrome.exe --remote-debugging-port=9222 --user-data-dir='
process = subprocess.Popen(address)
time.sleep(2)
options = webdriver.ChromeOptions()
time.sleep(2)
options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
time.sleep(2)
driver = webdriver.Chrome('chromedriver.exe',options=options)
actions = ActionChains(driver)
driver.get("https://chrome.google.com/webstore/detail/martian-wallet-aptos-sui/efbglgofoippbgcjepnhiblaibcnclgk")
driver.find_element("xpath","/html/body/div[3]/div[2]/div/div/div[2]/div[2]/div").click()
popup shown right after this script cannot be handled with switch_to.window or driver.switch_to.alert functions.
Or is there another way for downloading chrome extension?
CodePudding user response:
We cannot interact with those kind of popups through selenium because they are not part of the HTML. When the popup opens, you can accept it by pressing first the left arrow on the keyboard and then the enter key. In python you can do this with pyautogui
:
import pyautogui
pyautogui.press('left')
pyautogui.press('enter')