Rectangle 27 1

driver isn't initialised if both the creation of PhantomJS and Firefox fail.

Add a check before closing:

if driver:

python - AttributeError: 'NoneType' object has no attribute 'close' - ...

python selenium-webdriver phantomjs
Rectangle 27 0

This is because the form doesn't have a class of "loginf", that's the value of the name attribute. You could try using an attribute selector:


Thank you, this was perfect. I may make another Q for this, but if you have a moment, this is my next problem. After I evaluated a page (put it credentials, and logged in) I want to go to another page. I know I can put another "" outside of the page.evaluate but inside the first, but cookies seem to be lost after this. Anyway to keep the cookies?

An alternative is to click on the link: <a href="/questions"><i class="fa fa-question-circle"></i>Questions</a> But I am not sure how to get that from just that.

Well for the first method, one thing you could do is grab the cookies inside the page.evaluate call and store it to a global that can access them later on in that first Try using page.cookies and page.addCookie to add back the pertinent cookies

For the alternative you proposed, you could use the same line of thinking as for getting the element with name loginf. document.querySelector("a[href=/questions]").click();

SyntaxError: DOM Exception 12: An invalid or illegal string was specified.    undefined:8 in querySelector   :8   :15
TypeError: null is not an object (evaluating 'document.querySelector("a[href='/questions']").click')    undefined:10   :15

jquery - Use Submit Button with PhantomJS - Stack Overflow

jquery button phantomjs submit
Rectangle 27 0

When you use custom elements your APIs are HTML attributes. For now you have to test in the browser with Jasmine or QUnit since Node and PhantomJS don't support custom elements yet. You test by creating an instance of the element, calling a public function on it, and asserting the result.

Services will be an interesting topic going forward. Right now you either include business logic in the custom element or have some external script calling public APIs on your custom elements and binding everything together.

angularjs - How to have routing and services in Polymer similar to Ang...

angularjs dependency-injection routing polymer
Rectangle 27 0

PhantomJS 1.x is based on a QtWebKit fork from year 2010. It is comparable to Chrome 13. The earliest mention of the srcset attribute that I found is from 2013.

PhantomJS 2 also doesn't support this property despite being based on a newer version:

As of May 2014 it is based on webkit 538.1 (7 months old).

As I found, Chrome started supporting this attribute from its 34th version. Then, based on your comment we can conclude that PhantomJS 1.9.0 which I am working with, does not support the attribute. Also, does the function, which I shared in my question, check this ability?

'srcset' attribute in PhantomJS - Stack Overflow

Rectangle 27 0

To only render part of a page you need to set the clipRect attribute for the page and then render it.

var clipRect = document.querySelector(selector).getBoundingClientRect();
page.clipRect = {
    left:   clipRect.left,
    width:  clipRect.width,
    height: clipRect.height

I don't understand the second part of your question. Phantom.js is headless meaning that there is no actual display that a user is looking at.

I understand that phantom.js is headless. What I need in particular is its ability to capture a webpage from what's visible in the browser viewport. Do you know of a way to do this?

Okay, I understand what you mean. I don't know for sure if PhantomJS works that way or not. I don't know if Phantom has any concept of a viewport or anything like that.

I see. I am looking for some sort of framework that does this or some function inside the chrome extension API that allows me to do this. If you have any pointers, I'd greatly appreciate it.

I'm sorry. I don't know of anything.

var clipRect = page.evaluate(function () {   return document.querySelector("#someid").getBoundingClientRect();  });

javascript - How to render part of a page with PhantomJS? - Stack Over...

javascript phantomjs
Rectangle 27 0

If you want to get the actual, literal value of onload, use $('body').attr('onload'). This will return the value of any attribute, for any element (assuming jQuery is being used). If not using jQuery, document.body.getAttribute("onload") should do the trick.

Keep in mind that since PhantomJS technically runs outside of the targeted page's DOM, you need to wrap any DOM scripts in page.evaluate:

page.evaluate(function () {
    // put your $('body').attr('onload') bit here.

Are you sure that jQuery is being injected properly? Try using the getAttribute method.

@gustavi: parsed your code again, here's what I found: it looks like a problem with your use of return. Try setting the value of a variable directly. Take a look at this code for an example.

jquery - get value of body onload javascript with PhantomJS - Stack Ov...

javascript jquery html phantomjs
Rectangle 27 -1

I just tried it and it didn't remove html strings from json.

Get JSON page content with PhantomJS - Stack Overflow

json phantomjs