How to open default browser in both PC and Mac using Excel VBA? - excel

I need to open a url in the default web browser using Excel VBA. It should work both in PC as well as Mac.
I also need to get hold of the browser instance so I can access its document object and read some of the html elements or anything from the page rendered in the browser.
I know how to open InternetExplorer using CreateObject which gives you back the browser instance. Maybe in Mac I can open the Safari browser the same way. But I want to open the default web browser and also get the browser instance.

I'd personally let Excel figure it out:
ActiveWorkbook.FollowHyperlink "https://www.google.com"
I can't test whether this works on a Mac (but I don't see any reason why it wouldn't).
Note that if you want to use the default browser, you won't be able to ensure that you can even get an object instance (i.e. Chrome, Firefox, Opera, etc., etc.). I'd display for the user in the browser, then grab the html from the same link concurrently with some other method.

Related

Finding Browser Type in CODED UI?

How can i get the browser type in CODED_UI. I am new to coded ui automation. can you please help me out. Using BrowserWindow can we get the browser type.
By default your Browser type on Coded UI will be Internet explorer. Coded UI Uses Selenium to test Non-IE browsers and you have to set the browser type you want before you launch the browser.
So the question of getting your current browser type will be irrelevant, since you are the one setting it. It will be something like this,
BrowserWindow.CurrentBrowser = "Chrome";
Chrome = BrowserWindow.Launch(new Uri("http://yourwebsite.com"));
but, for some reason you do not know what your current browser is you can give a shot at,
browser.ClassName;
Note: It does not tell u explicitly, you have to extract it.

Getting the current page in TestComplete

I am writing a Script for TestComplete using JScript.
According to the documentation I can get the current page using the line:
page = browser.Page("*");
But instead I get a message: waiting for "*" and after that an error that the page "*" was not found.
Maybe I got something wrong there. What I am looking for is a method that gives me the Page Object for the current page I am on. Can anyone help me and tell me if such a method exists.
I want to avoid using NameMapping because in there the objects are fixed in their containers. In the project I test these containers may change so I use xpath recognition all the way through.
The code you specified should work if:
The browser variable contains a reference to a specific browser (e.g. Sys.Browser("firefox")).
The browser variable is the current browser (Sys.Browser()) and the current browser is set. The current browser is set when you call the Run or Navigate method of a browser object (e.g. Browsers.Item("firefox").Run();).
You have a page opened in the current browser.
The browser version is supported. Make sure that you have the latest version of TestComplete (11.11 by the moment) to be sure that your browser is supported.

node.js cheerio (scraping) live updating page

There is a webpage with live text data in a span tag that updates without the page refreshing. Is it possible to use cheerio or maybe another node.js module to get the page info and keep it open so node.js also sees the updates?
I would like to not keep re-requesting. As A human with the webpage open in the browser i do not need to refresh so logically the same should be doable in node.js
True?
You can use phantomjs
It's like a real browser but without window.
You can handle all browser event, so you can know when an element is added to page.

chrome.runtime has no method 'connectNative'

I am working on a Chrome extension that needs to call a native application.
As per Google documentation, we are using the chrome.runtime.connectNative method.
However in our extension, it seems that the chrome.runtime object has no method 'connectNative'. When we display the list of methods of the chrome.runtime object, we get the following list (printed by console.log("" + Object.getOwnPropertyNames(chrome.runtime));
getManifest,getURL,reload,requestUpdateCheck,connect,sendMessage,onConnect,onMessage,id
We are using Chrome 31.0.1650.63 on MacOS X 10.8.5 . We have also tried with Chrome Canary (version 34.0.1767.0 canary), we have the same error, with a slightly different list of methods for chrome.runtime:
getManifest,getURL,setUninstallUrl,reload,requestUpdateCheck,connect,sendMessage,onConnect,onMessage,id
So, in both cases (regular Chrome and Chrome Canary), we don't have the 'connectNative' method.
This does not seem to be a permissions problem, our extension manifest does have "nativeMessaging" in the permissions attribute. When we click on the permissions link in the Chrome extension settings, we can see that the extension can "communicate with cooperating native applications".
(sorry I couldn't post screenshots or the full manifest, StackOverflow won't let me paste things that even remotely look like I'm posting an image since I don't have enough reputation....)
Are we missing something ?
The list of properties of chrome.runtime you are getting indicates that your code is running as a content script. Most chrome.* APIs are not available to content scripts. They can only be used from background or event pages, popups, or other extension views you define. So you can use regular extension messaging from your content script to a background or event page, which in its turn can call your native app.

How to open new window's from XUL Browser?

I'm wondering, is it even possible to treat the request for the Xul Browser component to open a new window? I tried changing the window.open function, but looks like it's never called.
All links that open in a new window are not opening in my application.
I found this page on the subject, but the provided solution is showing no different behavior.
Any hint on this?
(by the way, I'm developing a stand alone application, not a Firefox's extension)
I'm assuming you are in a XULRunner application, and that you are trying to load a chrome URL from a non-chrome source in a browser (e.g. HTTP or local file). While enabling UniversalXPConnect and UniversalBrowserWrite can be helpful, they are also a security risk (since any arbitrary script on the web could use them), so they tend to be disabled in browsers (for example, running that line in Firebug will give you an exception):
>>> netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect UniversalBrowserWrite");
Error: A script from "http://stackoverflow.com" was denied UniversalXPConnect UniversalBrowserWrite privileges.
How about you try using codebase security principals and see if that makes a difference? (http://www.mozilla.org/projects/security/components/signed-scripts.html#codebase). For me in Firebug it does allow me to get the additional permissions after I OK it with a big, nasty looking dialog), but still doesn't allow me to open a Chrome URL with window.open. The next step is probably to try changing your conf file to use contentaccessible so that the relevant parts of your content are accessible (see https://developer.mozilla.org/en/Chrome_Registration#contentaccessible).
To avoid the nasty message when elevating permissions, you could try setting permissions for the right files automatically as described at http://forums.mozillazine.org/viewtopic.php?f=38&t=1769555.
Also, make sure you check the browser type (https://developer.mozilla.org/en/XUL/Attribute/browser.type). If the browser type is not chrome, then it might be worth trying making it chrome and seeing if that makes a difference.
If any of my assumptions are wrong get back to me and I will try something else.
does normal js not work?
window.open(url,windowname,flags);
There are two ways that I know of.
The first is to set the browser.chromeURL preference to a chrome URL that contains a <browser type="content-primary">. The page that the content window tried to open will load into the given browser.
The second is to set the property window.browserDOMWindow with an object that you define to implement the nsIBrowserDOMWindow interface. This allows you to divert the open call into a tab, if you are using a tabbed interface. Note: the tabbed browsing preferences must be set to allow windows to be diverted into tabs, otherwise XULrunner will fall back on browser.chromeURL.

Resources