pywinauto: accessing chrome gui - google-chrome

I am trying to select a printer and print on chrome browser, using pywinauto, but I am not able to access the gui components. I can see the components in Microsoft Inspect.exe in UIAutomation mode. (See screenshot).
I have started chrome with --force-renderer-accessibility flag.
I tried several things but I am not able to access anything in the chrome window. Is it possible to access the chrome gui components using pywinauto?
screenshot: ]1

Probably you use default backend="win32" which is used when you call Application(). To use MS UI Automation you have to set backend="uia" when instantiating Application object:
app = Application(backend='uia').start('chrome.exe <other params>')
My student wrote example script dragging file from explorer.exe to Google Drive in Chrome. Is it working for you?
P.S. If you already use backend='uia', please provide more detailed description with some code and output.

Related

Can i debug html page on run-time execution?

I am working on HTML page and using angular js.
I Want to see how many records my database collection has in run-time.
Is there any way to trace it, like we debug Java class.
You can set break point by using Chrome dev tool.
Open Chrome Dev Tool (Press F12)
Click Sources Tab
Select your JS file from left panel
Click on the line no to set the breakpoint
No..I think it's not available like u want to see data.
But u can do debug through the browser by inspecting elements.and My suggestion is to write business logic in ur language (C#,java....)and make service.And consume from client side.There u can debug easily.
In client side usually, we get an error in syntax or library compatibility.
You can debug all your JavaScript code using developer tools in Chrome for example and its debug functionality.
IDE like VSCode has also a built-in functionality for debugging JavaScript code directly from the IDE for example.
Then if your question is to see live your database from the browser. Nope, you cannot do that. There is nothing related between a front-end application and the connected database directly from the browser.
Then maybe there are few chrome extensions which could allow you to connect to your db and see real time it. But this is not a built-in feature.

How do I programmatically create a DragEvent?

This page describes the api for programmatically creating an event. Looking at the list, it indicates that Chrome and Safari do not support this api for creating DragEvents.
I'm trying to write automated tests for native html5 drag and drop behavior in an angular app. How can I programmatically mimic drag and drop events so I can do that?
You may want to use action chains (from selenium): https://code.google.com/p/selenium/wiki/AdvancedUserInteractions#Generating_Action_chains
We've used them on a non-angularjs app in the past for drag-drop. Anyway, as protractor (angularjs defacto tool for testing e2e apps) uses selenium webdriver, I bet you can use even protractor (https://github.com/angular/protractor) to accomplish that (with the object "browser.webdriver".
From protractors doc:
The browser.get method loads a page. Protractor expects Angular to be present on a page, so it will throw an error if the page it is attempting to load does not contain the Angular library. (If you need to interact with a non-Angular page, you may access the wrapped webdriver instance directly with browser.driver).
You're better off using the following protractor API:
https://code.google.com/p/selenium/source/browse/javascript/webdriver/actionsequence.js
You'll most likely want to use the following pattern:
browser
.actions()
.dragAndDrop(myEle, {x:100,y:100})
.perform();

Automate Chrome console from Desktop app?

I'd like to be able to send info to the Chrome developer console from my application.
For example, my app has some json. I'd like this json to show up in either an existing, or newly created instance of the chrome dev tools console.
Is this possible? If so, any pointers to examples? Note that the platform should be any language, not just javascript. And definitely not a site already running in Chrome. I'm interested in implementing this in another process.
Do you thought of running your app in an environment which is pretty much like a browser?
Node.js
or (this is a whole webkit browser)
phantom.js
Otherwise you could call Chrome directly via commandline and try to simulate the dev tools key stroke like explained here:
Is there a command line argument in Chrome to start the developer tools on startup?
The command of displaying something in the Chrome console is e.g. console.log and it is at the end Javascript. All Console commands are described here:
https://developers.google.com/chrome-developer-tools/docs/console-api
The closest I've seen so far is this library:
https://github.com/ccampbell/chromelogger
which seems to allow logging to the Chrome Console from lots of other server side apis, but no desktop APIs.
This can be done on Mac using osascript. Save the following as a script and run it:
#!/usr/bin/osascript -l JavaScript
var chrome = Application('Google Chrome');
//chrome.activate();
chrome.includeStandardAdditions = true;
var currentTab = chrome.windows[0].activeTab()
currentTab.execute({javascript: 'console.log("Hello")'})

Can you run multiple Chrome instances with different proxies?

I'm trying to run multiple instances of of Chrome with different proxies. Searching the web I've found that chrome supposedly supports 'chrome.exe --proxy-server="proxy:port" ' from the command line. But I've tried that and it doesn't work.
Is there any way to run multiple instances of Chrome with different proxies?
Thanks!
The answer from gengkev is correct. For all users combing from search engines who need a quick "copy and paste" solution, use this link target (windows):
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --proxy-server="http://proxy01.your.proxy:3128" --user-data-dir="%LOCALAPPDATA%\Google\Chrome-proxy01\User Data"
Chrome will create this new folder "Chrome-proxy01" on its own. With this you can have multiple chrome shortcuts using different proxy servers.
If you're running more than one instance of chrome with different flags, I think you need to specify different paths to --user-data-dir.
As mentioned in the previous answer, the way to do that is to:
Pass a --proxy-server parameter
Pass a different user data directory path for every launch with a different proxy server
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --proxy-server="http://proxy01.your.proxy:3128" --user-data-dir="%LOCALAPPDATA%\Google\Chrome-proxy01\User Data"
Where %LOCALAPPDATA%\Google\Chrome-proxy01\User Data folder needs to be unique for any new instance that uses a different proxy. So use %LOCALAPPDATA%\Google\Chrome-proxy02\User Data for the second launch, %LOCALAPPDATA%\Google\Chrome-proxy03\User Data for the third launch etc.
I would also highly advise to use the --no-first-run flag to get rid of the annoying popup that asks you whether you want to set chrome as your default browser every time you launch it with a new data directory
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --proxy-server="http://proxy01.your.proxy:3128" --user-data-dir="%LOCALAPPDATA%\Google\Chrome-proxy01\User Data" --no-first-run
Yes, you can run it. To do so:
Install the extension SwitchyOmega in the profiles that you want to use proxy.
Create a profile with your desired name and enter the details of the proxy that you wish to use.
Save the changes using apply changes button.
Switch to your proxy using the extension button present on the top right corner of the chrome.
In addition I am also attaching extension screenshot:
As of 2014-10-05, the easiest way to run multiple versions or instances of Chrome is to use Google Chrome Portable, downloaded from:
http://portableapps.com/apps/internet/google_chrome_portable
Currently I'm running 4 separate instances of Google Chrome v37.0.2062.124. One instance is installed and three other instances of Google Chrome are portable.
Here's how my Windows 7 Taskbar looks like when all 4 instances of Chrome are opened:
http://image.bayimg.com/a024621496637cbdc2ad85324ed5e8e07b9f5453.jpg
If you want to change Google Chrome icon that is shown on the Windows Taskbar once Google Chrome is started, then you should follow this link:
https://superuser.com/questions/613851/is-it-possible-to-customize-taskbar-icons-if-so-how
The answer is given in comments: you need to change icons that are stored in chrome.dll using Resource Tuner (use Trial version) or Resource Hacker (free).
When you run totally separate instances of Chrome, you can make those separate Chrome instances use different proxies through Chrome settings of that particular instance of Chrome.
You can make multiple "people" (settings > manage other people > add person). You can then open a instance for each person(you don't have to login to google for the other "people"). Then you can configure a proxy for that instance.
To get the menu that's shown in the picture just click on your profile icon on the top right.

How would I go about creating a custom protocol that would always open an address with a specific browser?

Okay, so I'm a student programmer in my college's IT department, and I'm doing browser compatibility for a web form my boss wrote. I need the user to be able to open a local file from a shared drive with a single click.
The problem is that Firefox and Chrome don't allow that for security reasons. Thus, I'm trying to write a custom protocol of my own to open an address in Internet Explorer regardless of the browser being used.
Can anyone help me with this? I'd also be willing to try an alternative solution to the problem.
The below worked for me, is this what you mean?
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\foo]
#="URL: foo Protocol"
"URL Protocol"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\foo\DefaultIcon]
#="C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\foo\shell]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\foo\shell\open]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\foo\shell\open\command]
#="C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe \"%1\""
Just to note, I'm running Win7Pro, so you may have to move around file path(s) to conform to your environment.
And if that doesn't work, create a proxy between the protocol and the browser, pass the argument(s) from foo:// to that, parse what's necessary, then hand it off to IE using start iexplorer.exe "args".
I'm unsure whether I understand your question, if it is how do I open local files using chrome/firefox, this is your anwser:
First a disclaimer, I have never done this and cannot vouch for the accuracy of my response
IE
Microsoft's security model is pretty fail so you can go right ahead and open these files
FireFox
Some quick googling found that Firefox can do this after either editing prefs.js as outlined here or installing an addon called LocalLink
Chrome
Practically impossible due to its security, until now when locallink was ported to chrome.