Skip to content

Instantly share code, notes, and snippets.

@AlexP11223
Created January 6, 2014 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexP11223/8286069 to your computer and use it in GitHub Desktop.
Save AlexP11223/8286069 to your computer and use it in GitHub Desktop.
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