Read Internet Explorer console output with Selenium - python

I'm working on testing automation in Internet Explorer 11 with Selenium and I'm looking to read any console output for errors. However, any research I pulled up lead to a 2 year old response saying that the IE driver doesn't support reading logs of any kind (see here). Has there been any update to this issue? If not, is there any workaround to reading JS errors in IE with Selenium?

No, there is no change to the log API not being implemented in the IE driver. One reason for this is the arrival of the W3C WebDriver Specification, which does not define any logging end points. Moreover, even if the driver were to implement the logging API, getting the console log in IE would still be impossible, since Internet Explorer does not provide any programmatic access to its debugging tools.
One approach to capturing JavaScript errors in IE is to set window.onerror and read any errors that occur there. Of course, this will not retrieve any JavaScript errors that occur during onLoad, or before the error handler is attached to the onError event. To accomplish that, another approach I've seen used is to use a proxy to inject the event handler script into the page before it gets to the browser. This blog post shows an example of how to do that. Even though the example is written in C#, the same technique can be applied in any of the other language bindings.

Related

Python interact with webrowser (opend by a user)

I am searching for a way which allows me to interact with a webrowser (Firefox,Chrome/Chromium,Edge are the most important).
I am currently using pyautogui, to locate login,password fields to put the login data into them. But since you can extract much easier informations when you can use IDs or xPath or other identifiers on webpages, it would make sense to use that.
I tried Firefox with selenium but I run in some problems. Can I attache it to a user created session (do I need the processID or something like that?). (Can I choose between the normal private session of the current profile?
I need a solution which works on Windows and Linux(it would be nice if the major Linux distros would support it. But the most important distros are Fedora/Ubuntu for me.) mac would be optional but since I do not got any mac I am not able to test it anyway.
The way with debugger mode or similar does not work really well for me since the browser needs to get started in a special way.
Would it possible to use something like this:
Can Selenium interact with an existing browser session? ,
When I can retrieve the this information some how form the existing browser?
driver.command_executor._url
driver.session_id
(But when I understand that currently it only works with browsers started with selenium?)
When I use Selenum and start a browserwindow with it can I login to a website and the user is logged in on the webside on his browser window too(if they us the same profile)? (Or does selenium separate cookies?)
If you need additional information or have some hints please post them so I can see them.
Thank you in advance for your help
It seems that it is not possible to connect to a web browser which was opened by the user to my understanding. How ever I found two possible solutions which I am currently trying to evaluate.
Using pyautogui to access the web browser over scanned images and control it with keyboard and mouse. (It is possible to access the console with the right combinations too).
The other solution is maybe more stable. Writing an browser extension which controls the browser.

Access browser logs in Selenium?

Is there a way to access logs on the browser made by the sever in Selenium? For example, if the site executed a console.log("Test."), can a Selenium test case access that log? Any help would be appreciated! (Preferably in Python).
Thanks!
~Carpetfizz
You could inject javascript and override the log function (as reading the log is not permitted from JS).
See http://tobyho.com/2012/07/27/taking-over-console-log/ for an example and there are many SO questions on this topic.
The problem with this is that it still can't get the logs which happened prior to injection.
It gets easier if you override this in the test deployment directly.

Capturing browser specific rendering of a webpage?

Is there any way to capture (image, pdf etc) how a webpage will look like in lets say chrome or I.E? I am guessing there will be different ways to do this for different browsers but is there any API, library or addon that does this?
Use selenium webdriver (has a python api) to remote control a browser and take a screenshot. Supports all major browsers as far as I'm aware.
Yes there are few wonderful websites providing this service and also some kinds of primitive to some advanced API services for capturing browser screenshots.
Browsershots.org
Its quite slow most of the times, may be due to the heavy traffic it has to withstand. However its one of the best screenshots provider.
[LINK]http://browsershots.org/xmlrpc/ Check this url to understand how to use the XMLRPC based API for browsershots.
And if you want some primitive and straight forward type thumbnailing services, may be the following sites work good for you.
http://www.thumbalizr.com/
http://api1.thumbalizr.com/?url=http://acpmasquerade.com&width=some_width
I checked another website webshotspro.com and when I queued one for a snapshot, it said my queue was behind 7053 other requests. the loading icon keeps rotating :P
Give a try with the XMLRPC call from Browsershots.org

python web script send job to printer

Is it possible for my python web app to provide an option the for user to automatically send jobs to the locally connected printer? Or will the user always have to use the browser to manually print out everything.
If your Python webapp is running inside a browser on the client machine, I don't see any other way than manually for the user.
Some workarounds you might want to investigate:
if you web app is installed on the client machine, you will be able to connect directly to the printer, as you have access to the underlying OS system.
you could potentially create a plugin that can be installed on the browser that does this for him, but I have no clue as how this works technically.
what is it that you want to print ? You could generate a pdf that contains everything that the user needs to print, in one go ?
You can serve to the user's browser a webpage that includes the necessary Javascript code to perform the printing if the user clicks to request it, as shown for example here (a pretty dated article, but the key idea of using Javascript to call window.print has not changed, and the article has some useful suggestions, e.g. on making a printer-friendly page; you can locate lots of other articles mentioning window.print with a web search, if you wish).
Calling window.print (from the Javascript part of the page that your Python server-side code will serve) will actually (in all browsers/OSs I know) bring up a print dialog, so the user gets system-appropriate options (picking a printer if he has several, maybe saving as PDF instead of doing an actual print if his system supports that, etc, etc).

Determine current Mac Chrome web page using Python

Is there a way to determine programmatically, using Python, which web page is currently active in Google Chrome?
Google Chrome for Mac has added the AppleScripting method for getting the URL.
Here's the Chromium AppleScript SDK
https://sites.google.com/a/chromium.org/dev/developers/design-documents/applescript
Example from the page linked below:
tell application "Google Chrome"
get URL of active tab of window 1
end tell
More examples here:
http://laclefyoshi.blogspot.com/2010/10/google-chrome-ver.html
Not yet, it seems. Such tasks are done, with other browsers, via the Applescript interface, but, as this thread shows, while hotly requested for Chrome on the Mac this feature is not there yet.
(Once a Mac app does get a good Applescript interface, there are several ways to use that interface from Python, without needing to actually involve Applescript as a language -- this has been touched upon on other SO questions about other apps -- but the problem is that Chrome in particular doesn't yet support this quintessentially Mac-ish functionality).
Given the insistence of the request I'd expect somebody to eventually roll up their sleeves and contribute a patch for the purpose, but it doesn't seem to have occurred yet.

Categories

Resources