Created
January 6, 2014 17:16
-
-
Save AlexP11223/8286069 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace WebViewHelpers | |
{ | |
public static class WebViewHelper | |
{ | |
// returns Javascript XPath query string for getting a single element | |
public static string GetJsSingleXpathString(string xpath) | |
{ | |
return | |
String.Format( | |
"document.evaluate(\"{0}\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue", xpath); | |
} | |
// returns Javascript XPath query string for getting a collection of elements | |
public static string GetJsXpathString(string xpath) | |
{ | |
return | |
String.Format( | |
"document.evaluate(\"{0}\", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null)", xpath); | |
} | |
// returns coordinates of top-left corner of the element (probably relative to the page) | |
public static Point GetElementPosition(dynamic element) | |
{ | |
dynamic rect = element.getBoundingClientRect(); | |
using (rect) | |
{ | |
return new Point(rect.left, rect.top); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment