alwex / php-casperjs

simple PHP wrapper for CasperJS
MIT License
182 stars 71 forks source link

how to send value from casper to php variable? #16

Closed lesterjanpearson closed 7 years ago

lesterjanpearson commented 9 years ago

example this is my code:

public function get_iframe_name($class) { $fragment = <<<FRAGMENT casper.then(function() { var iframe_name = this.evaluate(function() { var x = document.getElementsByClassName('$class'); return x[0].name; }); console.log(iframe_name); });

FRAGMENT;

    $this->_script .= $fragment;

    return $this;
}

I would like to get the value of iframe_name. I actually need the value to use on the next function to access the iframe, because that value is dynamic.

alwex commented 7 years ago

I don't think there is a way to use intermediate returns from casperjs as it is all executed in a separate process and php is not able to interact with the JS process during it's execution. I think you should add a custom selector on the iframe or to use another kind of CSS selector to achieve it like "body > iframe"