Strange bias with Watir / Capybara and PhantomJS

I want to locate elements on a page using Watir and PhantomJS. My second approach using Capybara resulted in the same bias.

While the items on the left side look good, the right side is offset:

enter image description here I took a screenshot before and after I grabbed the positions for each element with element.wd.location

, but the offset is always the same. I've used evaluate_script

it .getBoundingClientRect()

with Capybara too.

One thing looks suspicious to me: the search input box is not loaded correctly and not only displays misalignment but also a different size and the magnifying glass is not displayed. I don't know if this is causing the bias.

I tested it with pure PhantomJS 2.1.1 ( phantomjs file.js

):

var fs = require('fs');
var page = require('webpage').create();

page.viewportSize = {
  width: 1024,
  height: 768
};

page.open('http://en.wikipedia.org/', function() {
  var positions = page.evaluate(function() {
    positions = [];
    elements = document.getElementsByTagName('IMG');
    for (var i=0, l=elements.length; i<l; i++) {
      pos = elements[i].getBoundingClientRect();
      positions.push(pos.left + ' ' + pos.top);
    };
    return positions;
  });

  fs.write('test.txt', positions.join("\r\n"), 'w');

  page.render('test.png');
  phantom.exit();
});

      

Same result: if you open test.png, you see the image on the right (left: 952px, top: 259px), but test.txt shows it is shifted to the left (left: 891px).

Do you know what could be causing this problem?

+3


source to share


2 answers


Do you know what can cause this displacement?

Bug in PhantomJS v2.1.1 or embedded Qt WebEngine.

Is there a workaround?

Not.

But I want it to work, how?



Fix it or hire someone to fix it or wait for it to be fixed.

Please note that the issue no longer occurs in version 2.5, but it is still in beta:

https://github.com/ariya/phantomjs/milestone/16
https://bitbucket.org/ariya/phantomjs/downloads/

Here is a screenshot taken with phantomjs-2.5.0-beta:

enter image description here

+2


source


This seems to be a problem in PhantomJS .

On the GitHub thread of @dantarion's problem seems to have found a solution:

I control this too. My fix is ​​to run the following on the page in the evaluation box to force PhantomJS to display the height in the right viewport. It works for my use case, and while I want to see that it is fixed in 2.2 since its issue was still a problem, I thought I would post here.



    document.getElementsByTagName("body")[0].style.overflow = "hidden";
    document.getElementsByTagName("body")[0].style.height = "1080px";
    document.getElementsByTagName("body")[0].style.maxHeight = "1080px";
    document.getElementsByTagName("html")[0].style.overflow = "hidden";
    document.getElementsByTagName("html")[0].style.height = "1080px";
    document.getElementsByTagName("html")[0].style.maxHeight = "1080px";

      

This seems to be the solution to the problem. The only problem is that it background-size: cover

can be turned off (as reported by @ Luke-SF).

0


source







All Articles