I am trying to automate a plugin in chrome browser. It requires opening an inspect window and perform operation on inspect window. I am able to open inspect window using robot class and navigate among inspect GUI elements but cannot do HTML DOM operation in inspect window. Inspect window contains iframes but I am not able to switch to those iframes from main page. When I try to list the iframes on a active page it only shows iframes from the main page not from the inspect window. I want to switch to inspect window using iframes or any other way if there is any. The code I have written so far is
from pyrobot import Robot
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
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)
robot = Robot()
robot.addExtension() # customized Robot class to add extension
robot.newtab() # customized Robto class for new tab
browser.switch_to.window(browser.window_handles[1])
browser.get('http://www.walmart.com')
time.sleep(8)
robot.inspectElement() # Customized Robot class for inspecting (Ctrl+shift+i)
While you create chromedriver object in C# this will work,
you need to provide profile by adding arguments in chromeoptions,
ChromeOptions options = new ChromeOptions();
options.AddArguments("--auto-open-devtools-for-tabs");
browser = new ChromeDriver(DrivePath, options, TimeSpan.FromSeconds(100));
You can also try to press F12 it will open inspect window
then you can use Robot class or Windows. Forms library for automation scripts manae multiple window Forms.
Your code is in python same answers are alredy provided for java and C#.
You can also refer more at:
How to open Chrome Developer console in Selenium WebDriver using JAVA
How do you automatically open the Chrome Devtools tab within Selenium (C#)?
Related
I want test the IE mode for Edge browser with Selenium. I found the solution on the MS site here:
https://learn.microsoft.com/en-us/microsoft-edge/webdriver-chromium/ie-mode?tabs=java
I am using the following code as given in the above link:
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerOptions;
InternetExplorerOptions ieOptions = new InternetExplorerOptions();
ieOptions.attachToEdgeChrome();
ieOptions.withEdgeExecutablePath("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");
WebDriver driver = new InternetExplorerDriver(ieOptions);
I can get the error that the methods "attachToEdgeChrome()" and "withEdgeExecutablePath()" are not defined in the InternetExplorerOptions. Is there anything I am missing here?
Note: My selenium jar is selenium-server-4.0.0-alpha-2.jar
As per the ChangeLogs 0f Selenium v4.0.0.0-alpha-2:
Add Chromium-based Edge support. This involves adding a new Chromium driver to the tree too.
So ideally, the code block from the documentation Use Internet Explorer Driver to automate IE mode in Microsoft Edge should have worked seamlessly.
However, as per best practices instead of using the alpha and beta releases, you should always prefer the GA releases to execute your tests and you can pickup anyone from the following options:
Selenium v4.1.3
Selenium v4.1.2
Selenium v4.1.1
Selenium v4.1.0
Selenium v4.0.0
I'm using Selenium to automate certain stuff in Chrome and I know how to open multiple tabs, but is it possible to open Chrome itself multiple times?
Right now, when I want to open a new Chrome app the old one closes. I want it to stay open.
every time you want to open a new Chrome Browser you have to create a new instance of the webdriver.
from time import sleep
from selenium import webdriver
fist_driver = webdriver.Chrome(executable_path="/path/to/chromedriver")
fist_driver.get("https://google.com")
second_driver = webdriver.Chrome(executable_path="/path/to/chromedriver")
second_driver.get("https://ifconfig.me")
sleep(5)
# using for loop
for _ in range(2): # How much browser you want to open
driver = webdriver.Chrome(executable_path="/path/to/driver")
driver.get("https://google.com")
sleep(5)
I am using Python's Selenium Webdriver with Firefox, and trying to
navigate to a webpage that embeds a frame
open the devtools menu (Ctrl+Shift+K in Firefox)
select this other iframe from the iframe context picker exposed by devtools.
Question:
How to achieve this?
What I've tried:
My current script reads
#!/usr/bin/env python
from selenium.webdriver import Firefox, DesiredCapabilities, FirefoxProfile
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
import time
import traceback
import os
options = Options()
options.add_argument("-devtools")
webdriver = Firefox(options=options)
webdriver.get(<url that will embed the iframe>)
try:
<do a bunch of stuff that will trigger the appearance of the iframe>
except:
pass
try:
time.sleep(3)
with webdriver.context(webdriver.CONTEXT_CHROME):
ifr =
webdriver.find_element_by_class_name("devtools-toolbox-bottom-iframe")
except Exception as error:
traceback.print_exc()
This doesn't complain, because it does find an element with class devtools-toolbox-bottom-iframe. My problem is that I do not know what to do with it afterwards to access the iframe-selection menu underneath. That element has a tag of browser, i.e. looks like this:
<browser type="content" flex="1" class="devtools-toolbox-bottom-iframe" height="250" aria-label="Developer Tools" src="about:devtools-toolbox" session_id="910"/>
This old answer of mine no longer works, because back then this same element was an iframe and I could simply switch to it with
webdriver.switch_to.frame(<iframe>)
I have also tried clicking it (with ifr.click()) to no effect: I see nothing happening in the Firefox window that the script opens (no errors either though).
I have been searching on the internet using Selenium (Java) interacting with Google Chrome Extension but have not been able to find an answer.
First Question
Is there a way to launch the chrome extension since Selenium only interact with WebView but not on the chrome extensions button in the browser ?
I try this method
"chrome-extension://id/index.html" but the extension did not launch as expected. I like find if there is another way to launch a chrome extension through selenium
Second Question
I am trying to click on the elements in a chrome extension with Selenium webdriver. How do I do it ? I tried the driver.CurrentWindowHandle , but it does not detect the chrome extension.
Thanks
Below is the solution with pyautogui (similar to autoit in java - so you can extend the same solution for java also).
Pre-Condition:
save the extension image in the project folder (I saved it under "autogui_ref_snaps" folder in my example with "capture_full_screenshot.png" name
Python:
Imports needed
from selenium import webdriver
from selenium.webdriver import ChromeOptions
from Common_Methods.GenericMethods import *
import pyautogui #<== need this to click on extension
Script:
options = ChromeOptions()
options.add_argument("--load-extension=" + r"C:\Users\supputuri\AppData\Local\Google\Chrome\User Data\Default\Extensions\fdpohaocaechififmbbbbbknoalclacl\5.1_0") #<== loading unpacked extension
driver = webdriver.Chrome(
executable_path=os.path.join(chrome_options=options)
url = "https://google.com/"
driver.get(url)
# get the extension box
extn = pyautogui.locateOnScreen(os.path.join(GenericMethods.get_full_path_to_folder('autogui_ref_snaps') + "/capture_full_screenshot.png"))
# click on extension
pyautogui.click(x=extn[0],y=extn[1],clicks=1,interval=0.0,button="left")
If you are loading an extension and it's not available in incognito mode then follow my answer in here to enable it.
Try to click on extension with this JsExecutor method:
driver.execute_script("window.postMessage('clicked_browser_action', '*')")
While running WebDriver automation scripts I came across a situation where it is trying to open a page which contain one segment with live camera (Made with Java applet). Once script reaches to this page - a Security Warning alert (with allow and not allow) shows up and blocks the execution process. Is this something that anyone faced before - actually I am looking for an option to block this security warning to get displayed on the page.
A popup is coming where i want to click on the "Allow". How to move the focus to the new popup window and click on Allow.
Can anyone please help me for the above problem?
I was having problems accepting the java applet "Allow"
My solution was to create a firefox profile that had the settings to always activate the plugin:
FirefoxProfile fp = new FirefoxProfile();
fp.setAcceptUntrustedCertificates( true );
fp.setPreference( "security.enable_java", true );
fp.setPreference( "plugin.state.java", 2 );
WebDriver d = new FirefoxDriver( fp );
Where plugin.state.java:
plugin.state.java = 0 --> never activate
plugin.state.java = 1 --> ask to activate
plugin.state.java = 2 --> always activate
This might get you closer...
Selenium uses a different firefox profile because Java was inactive for me and I did not have my firebug plugin in the Firefox browser Selenium launched. I would have to open another Firefox to use Firebug.
I found my default Firefox profile by searching %appdata% in the start menu then clicking on Roaming/ Mozilla/ Firefox/ Profile/ and then it gave my default profile name.
You can also open the firefox help menu (? logo) & click troubleshoot info... click Show Profile Folder
I then configured selenium to use my default profile so Java was enabled and Firebug was available in the browser Selenium launched:
Make sure that you use "/" in selenium even though it may use "\" in the windows path location
fp = webdriver.FirefoxProfile('C:/Users/xxx/AppData/Roaming/Mozilla/Firefox/Profiles/41s7nq9o.default')
driver = webdriver.Firefox(fp)
driver.get('www.stackoverflow.com')
where 41s7nq9o.default is the name of your default profile