使用Selenium WebDriver访问和处理Chrome扩展程序弹出窗口 [英] Access and handle chrome extension popup using selenium webdriver

查看:612
本文介绍了使用Selenium WebDriver访问和处理Chrome扩展程序弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Selenium Webdriver安装IBM DAP chrome扩展.我无权访问crx文件.因此,我尝试通过chrome网络商店直接将其安装为插件,如下所示:

I am trying to install the IBM DAP chrome extension using Selenium webdriver. I don't have access to crx file. So, I tried to install it directly through the chrome web store for plugins as:

browser = webdriver.Chrome()
browser.get('https://chrome.google.com/webstore/detail/dynamic-assessment-plugin/fnapgcgphlfhecijolobjodbbnjjpdga')
browser.maximize_window()
browser.implicitly_wait(5)
browser.find_element_by_css_selector("body > div.F-ia-k.S-ph.S-pb-qa > div.h-F-f-k.F-f-k > div > div > div.e-f-o > div.h-e-f-Ra-c.e-f-oh-Md-zb-k > div > div").click()
browser.switch_to_alert().accept()

,但是此代码无法访问弹出窗口,并且无法单击添加扩展名"按钮.如何访问弹出窗口并单击添加扩展名"?

but this code is not accessing the pop up window and is not able to click the 'Add extension' button. How to access the pop up window and click on the 'Add extension'?

推荐答案

在@Navarasu解决方案之后,我从

Following @Navarasu solution, I copied pyrobot.py file from here. It worked perfectly fine for me.

from pyrobot import Robot
from selenium import webdriver
import time

browser = webdriver.Chrome()
browser.get('https://chrome.google.com/webstore/detail/dynamic-assessment-plugin/fnapgcgphlfhecijolobjodbbnjjpdga')
browser.maximize_window()
browser.implicitly_wait(15)
browser.find_element_by_css_selector("[aria-label='Add to Chrome']").click()

time.sleep(3)
rob = Robot()
rob.key_press('tab')
rob.key_press('enter')

这篇关于使用Selenium WebDriver访问和处理Chrome扩展程序弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆