XPath function selectNodes does not wordk in Windows 8 - xpath

This small JavaScript snippet of code makes me mad since I installed Windows 8
xmlDoc=http_request.responseXML.documentElement;
var nodes = xmlDoc.selectNodes('/rfp_object/category');
Until that very moment everything worked fine for years, but now I meet trouble when using Windows 8.
The error says: The property or method selectNodes is not being supported by this object.
In Chrome, Firefox, Safari and Windows Vista it does what I was expecting. But under Windows 8 not. Even more peculiar is that it works fine in Development on an XP server, but not in production on Windows Server 2008.
Changing the selectNodes into getElementsByTagName('category') works great in this situation but is not an option, because I need to filter data in other occasions.
So what do I have to do, to make it work for Windows8 users like it used to work.
Any help will be higly appreciated.
Lourens

I think IE 10 makes responseXML an IE XML DOM document while with earlier versions of IE it is an MSXML XML DOM document. The methods selectSingleNode and selectNodes are part of the MSXML DOM API but not of the IE DOM API. I don't think IE provides XPath support for its DOM documents so you will need to decide whether you want to convert the responseXML into an MSXML DOM document along the lines of
var doc = new ActiveXObject('Msxml2.DOMDocument.6.0');
doc.loadXML(new XMLSerializer().serializeToString(http_request.responseXML));
to then use selectNodes on the doc variable or you will check whether the method IE offers like getElementsByTagName and querySelector allow you to find what you are looking for or you will need to check whether a Javascript implementation of XPath like https://github.com/ilinsky/xpath.js allows you to write the query you want.

Related

Is there a platform-independent method for opening links in an Outlook-addin?

I have an outlook-addin written in Angular framework, which communicates with the Outlook through the office-js.
My goal is to implement a service that opens any kind of URLs/links in any mainstream platforms where outlook is available, to be specific: in Google Chrome, Safari, Firefox, Opera, Internet Explorer, The MacOS desktop Outlook - old and new versions either, and most of the Windows desktop Outlook versions (2016, 2019, O365). But unfortunately I can not find a way that works in all of the platforms, and I want to avoid implementing it in a platform-dependent manner.
The first problem I encountered with, is that when I am trying to open links by a simple js function window.open(url) then the outlook versions that use Internet Explorer as an engine are failing to open URLs that contain the character #. That is because IE does not seem to be able to read this character and it cuts the URL in half by the # character and it completely removes the parts followed by the #.
https://en.wikipedia.org/wiki/County_Antrim#/media/File:Ballycastle_Harbour_-_geograph.org.uk_-_468327.jpg
window.open(
"https://en.wikipedia.org/wiki/County_Antrim#/media/File:Ballycastle_Harbour_-_geograph.org.uk_-_468327.jpg",
"_blank"
);
For example, if I try to open the URL above on Windows outlook 2019 which uses Internet Explorer as it's engine, then the url will look like this in the end:
https://en.wikipedia.org/wiki/County_Antrim
For a solution I've implemented a workaround that encodes the URL by a built-in function that comes with typescript which allows the IE to be able to open the link. By simply passing the encoded URL to the window.open() does not work because it concatenates the url with the host of my addin, which results in an invalid link.
window.open(
encodeURIComponent(
"https://en.wikipedia.org/wiki/County_Antrim#/media/File:Ballycastle_Harbour_-_geograph.org.uk_-_468327.jpg"
),
"_blank"
);
The host of my addin + the encoded URL:
https://localhost.eu.ngrok.io/https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FCounty_Antrim%23%2Fmedia%2FFile%3ABallycastle_Harbour_-_geograph.org.uk_-_468327.jpg
So I had to redirect manually with a simple html code as shown below:
redirect.html:
<html>
<head>
<script type="text/javascript">
window.onload = function (event) {
var regex = /\?url=(.*)/ig;
var match = regex.exec(location.search);
if (match && match[1] && match[1] !== "") {
location.href = decodeURIComponent(match[1]);
}
else {
document.body.innerHTML = "Redirect failed!";
}
};
</script>
</head>
</html>
typescript code:
url = "https://en.wikipedia.org/wiki/County_Antrim#/media/File:Ballycastle_Harbour_-_geograph.org.uk_-_468327.jpg"
window.open("./redirect.html?url=" + encodeURIComponent(url), "_blank");
Unfortunately, this method also has some flaws in the desktop outlook of MacOS. Redirecting makes the links open in a simple webviewer of the outlook application, and not in Safari as it is expected since the default browser is set to Safari in both of the system preferences and in the outlook browser preference. Despite the fact that it can open the links in this webviewer, I can not use it, because some of the webpages I want to navigate to does not support to be opened by the webviewer.
I was suspecting that this behaviour is caused by the relativity of the url ("./redirect..."). So I have tried building the URL by adding dynamically or even hardcoding the host of my addin to the beginning of the URL this way:
`${window.location.origin + window.location.pathname}/redirect.html?url=` + encodeURIComponent(url);
But there was no difference in the results by doing it, so I am guessing that referencing the host of the addin itself does not change quality or state of the URL, meaning that it is still managed as a relative link.
Since I had the opportunity to host the redirect.html from another server, I have tried referencing the redirect.html file from another host, and that way even the MacOS Outlook worked perfectly, proving my suspicion of the wrong management of relative links.
I have also tried using the function called openBrowserWindow provided by office-js the following way:
Office.context.ui.openBrowserWindow(url);
But this was also a dead-end, since this could neither handle the # character in IE nor it was supported in all of the platforms I need to use.
The last workaround I have tried is by completely reworking the service and instead of opening the links by using js or ts functions, I have tried binding the urls to the href attribute of <a></a> elements, however the application requirements exclude this method, as there are some links that are expected to be opened by double clicking, which can not be done with using an <a> tag as far as I know, at least not in an "hacky" way.
Which I would really like to know, what makes the links open in the webviewer of the MacOS outlook application instead of the default browser of the system? Is it a setting I am missing, or is there a way to force using the safari?
Did you try simply doing:
if (Office.context.ui.openBrowserWindow) {
Office.context.ui.openBrowserWindow("https://google.com");
} else
{
window.open("https://google.com");
}
Since openBrowserWindow is selectively not supported in OWA, window.open will automatically take over.

Firefox Dev Edition: shorter XPATH finder

how is it possible to easily obtain short form of XPATH through Inspector?
For example, if I try "Copy xpath" on web element I get pretty long response like this:
/html/body/div[6]/div[1]/div[1]/p[13]
Instead of this or similar:
//[#id='exeample_value']*
Since I need to cover a lot of these, do not want to loose time to shorten them manually. In older versions of Firefox I used plugins like Firebug and Firepath, but they seem not to be compatible with new FF versions (and FF Dev Edition).
The Firefox DevTools don't allow to copy relative XPaths yet (as of Firefox 58). Therefore I've filed bug 1410810 for it some time ago.

ABCPDF with Gecko rendering does not render the same in Firefox?

Right now I'm using the latest ABC PDF version, and use the Gecko rendering engine. However, I notice that there are small differences between the way Firefox renders the HTML I'm adding to my PDF, and the way ABC PDF interprets the HTML. I was wondering if there is anything that can be done against this?
I'm asking about Firefox specifically because I thought that browser used the same Gecko rendering engine as ABCPDF did, so I thought it would be 100% the same.
Does anyone know about this? Couldn't find much about this on the internet, though I do admit that I find it hard to come up with the correct search terms.
By default ABCpdf will use the 'print' css media type whereas Firefox will be using 'screen', this can be changed by setting the media property.
var doc = new Doc()
doc.HtmlOptions.Media = MediaType.Screen
If the differences are more subtle it may be worth taking a look at engine configuration.
It is important to note the Gecko engine used in ABCpdf is independent from the engine used in any local Firefox installation, it should be assumed that it will be different in both version and configuration.

Test success differences in different browsers

When attempting to click elements using a CSS selector, e.g
browser.find_element(:css, '.login').click
I am seeing different behaviours in different browsers. This is the behaviour I am seeing:
Chrome (35.0.1916.114) - works as expected
Firefox (24.0) - seems to ignore the command and move onto the next line of the test. Either that or it thinks it has clicked the element when it has not.
Safari (7.0.3 (9537.75.14) - complains that the element is not present. Interestingly, this one doesn't even seem to wait until the page has even loaded.
I have tried using a variety of web driver versions (2.42.0, 2.39.0, 2.33.0) and different browser versions with no success.
It turns out that my specific problem was that Firefox doesn't like targeting link elements inside lists, whilst chrome will do it fine. For example:
The following will not work in Firefox:
Browser.find_element(:css, '.list-item')
Whereas this will:
Browser.find_element(:css, '.list-item > a')
This may have been a unique problem for the site I was testing, but it is worth bearing in mind.

detecting FireFox4 browser

How to detect FireFox4 or any updated versions of FireFox, to include specific stylesheet?
Note: FF4 and FF5 gives font-size too small when printed. on screen its fine(FF3.0 to FF5).
You need to inspect the user agent string. How you do that wil depend on what technique you wish to use and what platform you are on. In PHP you can inspect the value of $_SERVER['HTTP_USER_AGENT'], or you can do it using jQuery as Eamorr says. It is also possible a number of other ways, you'll have to tell us more about your setup.

Resources