Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Saturday, August 29, 2015

iOS 8 Safari screenshots with variable browser header height

Capturing shots when a browser has variable header height
In iOS 8 Safari comes with a feature when browser's header might be 65px or 41px (when address bar is hidden on scroll, aka minimal-ui) .


For example to capture pages on iPad 2 one could use AShot utility with a strategy that can detect current height of browser's header.

int minHeader = 41;
int maxHeader = 65;
int minViewPortHeight = 960; // Height of viewport when address bar shown
HeaderDetectionStrategy strategy =
    new VariableHeaderDetectionStrategy(minHeader, maxHeader, minViewPortHeight);
new AShot()
  .shootingStrategy(new ViewportPastingStrategy(strategy))
  .takeScreenshot(webDriver);
When in JavaScript to guess the height of browser's header - whether address bar is shown, window.innerHeight property could be used.

Wednesday, June 10, 2015

TextArea scrollbar width in Firefox

To get scroll bar width of text area - use

element.offsetWidth - element.clientWidth

spent an hour fighting with scroll bar....

Sunday, September 8, 2013

Find elements by XPath with JavaScript (example)


Get elements from action menu on mail page of yandex.ru:

r = document.evaluate("//*[@class='b-toolbar__block b-toolbar__block_chevron']/a", document, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);

el = r.iterateNext();

while(el) { 
  if (window.getComputedStyle(el).display == "none") {
    continue; 
  } 
  console.log(el.getAttribute('data-action')); 
  el=r.iterateNext();
}