简体   繁体   中英

switch to add-on pop-up window interface selenium python

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

As you can see usually when we click on add-on icon it creates a "pop-up" or a "window", literally another html file as i evidenced., not embodied in main html. I wonder how to switch from main tab to add-on interface and work on it (like click button etc.) without using pyautogui & image detection: it would be too easy;)

I guess you are talking about frames. A frame is a part of a web page or browser window which displays content independent of its container, with the ability to load content independently (source: https://en.wikipedia.org/wiki/Frame_(World_Wide_Web) )

You can switch to another frame with the following command:

driver.switch_to.frame()

As parameter for the frame() function, you have 3 options: frame index (0,1,2, etc), name (an id that the developer has given to the frame, or webelement (ie a unique element in that frame, which you can find as every other element with:

driver.switch_to.frame(driver.find_element_by_...)

I hope I helped:)

I am not sure how to click add-on icon on Chrome just using Selenium. Actually, I don't think chromedriver has provided some methods to click on the chrome toolbar, so maybe you can't write codes to do it.

But, there is another way that works.

  • Right-click on the add-on icon
  • Select the last option Manage extensions on the list, a new tab opens which has url like this chrome://extensions/?id=cfhdojbkjhnklbpkdaibdccddilifddb .
  • Or, Select Options on the list, a new tab opens, url like this chrome-extension://cfhdojbkjhnklbpkdaibdccddilifddb/options.html .

在此处输入图像描述

In other words, all of the Chrome extensions configuration pages are actually HTML pages. So you can open the configuration page directly, and click button or do other actions you want.

extensionManagePage = "chrome://extensions/?id=cfhdojbkjhnklbpkdaibdccddilifddb";
driver.get(extensionManagePage);

// or

extensionOptionsPage = "chrome-extension://cfhdojbkjhnklbpkdaibdccddilifddb/options.html";
driver.get(extensionOptionsPage);

// click button etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM