I am trying to open the Chrome extension page ("chrome://extensions/") in Chrome as the last step of a local script (so I can finally reload an extension there).
Unfortunately I am failing with this. :-(
-> Python 2.7 for win 8.1 x64
import webbrowser
webbrowser.get().open("chrome://extensions/")
This with Chrome as standard browser only results in windows telling me not knowing how to handle this:
And when I call Chrome directly via...
webbrowser.get("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s").open_new_tab("chrome://extensions/"))
... or ...
import subprocess
subprocess.Popen([r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe', 'chrome://extensions/']).wait()
... or when I try to open the URL via windows run dialog ...
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "chrome://extensions/"
... it always just opens a new window with the New Tab page, while a HTTP(S) URL opens these calls correctly.
Has anyone an idea how to open this chrome-specific page?
I believe that by default accessing/passing chrome url's is disabled/sandboxed outside of chrome, but there are cli switches that can be passed to chrome that you can use to change this??
List of Chrome switches here
Extension code docs, this might help you if all you are trying to do is reload an extension. Instead of doing it through the chrome:// URI
Related
I need to enter a filepath to upload a file in a windows pop-up, How to handle it in selenium+python+robot framework?
Specifically for file uploads, one does not open the OS dialog and enter the path there. If you did make it work somehow, then it would be specific for Windows; but what if the case is ran on Mac OS? Or headless Linux?
For this purpose in Selenium there's a special method, available in SeleniumLibrary as the Choose File keyword. Through it the full path is set as the value of the input element handling the upload, and no OS modal is brought up.
Selenium even has some special code to transfer the file, if the browser is a remote one (e.g. the file is local for the execution machine, but the browser is running on a different, remote one).
I am trying to open chrome through a python script using subprocess but it is not allowing me to use a specified user data directory, and thus defaults to my default user data directory. I get a pop up error reading "Google chrome cannot read and write to its data directory".
Code:
if __name__ == '__main__':
subprocess.run([
'chrome.exe',
'--remote-debugging-port=9222',
'--user-data-dir="C:\\selenum\\ChromeProfile"'
])
I am using Windows 10. If I open chrome with git-bash with command...
chrome.exe --remote-debugging-port=9222 --user-data-dir="C:\selenum\ChromeProfile"
...then it works just fine. I'm thinking that this might be a permissions thing when running chrome out of a python script, but not certain.
How do I navigate and click buttons on an already open Chrome instance/window. So the scenario is, that an application named "ApplicationNAME" is installed on my Windows machine, but its not a Windows application, because when I run the application it is only opening a chrome instance (not the default Chrome browser). I am also able to see the Developers Tool of chrome, and I am able to inspect the elements which means a chrome instance is opened.
So the idea is to automate this Application using Python and Selenium. I am open for alternate suggestions too. Thank you!
I have used the below Python (3.7.3) code but it doesn't help, because it rather opens another Chrome browser or navigate to already open Chrome window rather than going into the desired "ApplicationNAME" chrome instance.
from pywinauto.application import Application, WindowSpecification
import time
import requests
import selenium
from selenium import webdriver
app = Application().start(cmd_line=u'"C:\\Program Files (x86)\\ApplicationName.exe" ')
chromewidgetwin = app[u'ApplicationName']
chromewidgetwin.wait('ready')
chromerenderwidgethosthwnd = chromewidgetwin[u'Chrome Legacy Window']
chromerenderwidgethosthwnd.click()
Driver = webdriver.Chrome ("C:\\chromedriver.exe")
Driver.switch_to_window('ApplicationName')
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://www.google.com')
Can someone help me with the above code. I expect this code to open a new tab in Firefox with google.com; instead this opens a new Internet Explorer tab.
Setting up geckodriver for Selenium Python resolves the issue I think.
It needs to set geckodriver path with FirefoxDriver as below code:
self.driver = webdriver.Firefox(executable_path = 'PATH\TO\geckodriver.exe')
Download geckodriver for your suitable OS from https://github.com/mozilla/geckodriver/releases
Extract it in a folder of your choice
Set the path correctly as mentioned above
IEDriverServer and GeckoDriver both of the WebDriver variants being/getting W3C Compliant and evolving with each day, it is quite possible that trying to use one of the variants gets hooked to other variant of Web Browser because of the following reasons :
Your Automated Tests may be running in an environment which is Manually Intervened by opening/closing of Internet Explorer and Firefox Web Browsers.
You have a (couple of) dangling instance of IEDriverServer within your system which needs to be cleaned up.
Solution :
Here are a few possible solutions for the issue you are facing :
Always be explicit mentioning the absolute location of the GeckoDriver while initializing the WebDriver / Web Browser instance as follows :
driver=webdriver.Firefox(executable_path=r'C:\path\to\geckodriver.exe')
Within the tearDown() method of your Test Execution always use quit() as follows :
driver.quit()
Before you start the Test Execution ensure there are no dangling instances of any WebDriver variant.
Incase your Test Framework leaves any dangling instances add the following Windows Based Command at the end of your script to kill the dangling WebDriver.
taskkill /F /IM <webdriver_variant>.exe /T
Periodically Cleanup your Project WorkSpace in your IDE.
Run CCleaner tool to wipe away all the OS chores before and after Test Execution.
When you uninstall any Browser (any Software) from your system use Revo Uninstaller which cleans up your Unused Registry Settings as well.
How do I change the browser used by the view(response) command in the scrapy shell? It defaults to safari on my machine but I'd like it to use chrome as the development tools in chrome are better.
As eLRuLL already mentioned, view(response) uses webbrowser to open the web page you downloaded. To change its behavior, you need to set a BROWSER environment variable.
You could do this by adding the following line at the end of your ~/.bashrc file:
export BROWSER=/usr/bin/firefox (if you would like firefox to be used).
I don't have Chrome installed, but by doing a fast search on Google, it seems its path is /usr/bin/google-chrome-stable; therefore, you could try export BROWSER=/usr/bin/google-chrome-stable instead. I didn't test it for Chrome though.
There is no current way to specify which browser to use to open the response, as it internally uses the webbrowser package. This package uses your default configured browser to open the current response.
You could always change the default browser to chrome on your system, that should make webbrowser use it.
This fixed it for me:
If you're on windows 10, find or create a random html-file on your system.
Right click the html-file
Open with
Choose another app
Select your browser (e.g Google Chrome) and check the box "Always use this app to open .html"
Now attempt to use view(response) in the Scrapy shell again and it should work.
Try this
import webbrowser
from scrapy.utils.response import open_in_browser
open_in_browser(response, _openfunc=webbrowser.get("/usr/bin/google-chrome").open)