Note that there are some explanatory texts on larger screens.

plurals
  1. POExecute javascript in selenium using php-webdriver-bindings-0.9.0
    text
    copied!<p>I'm trying to execute JavaScript in my selenium test suite but it's not working and I get no error feedback. It gracefully accepts whatever I enter as parameters to the execute function and passes the test. The following are combinations I have tried:</p> <pre><code>class TestingStuff extends PHPUnit_Framework_TestCase { protected function setUp() { $this-&gt;webdriver = new WebDriver("localhost", 4444); $this-&gt;webdriver-&gt;connect("firefox"); } protected function tearDown() { $this-&gt;webdriver-&gt;close(); } public function testSomething() { $this-&gt;webdriver-&gt;get('http://localhost/testdir/'); // Here is the execute function $this-&gt;webdriver-&gt;execute('alert', 'Hello'); $this-&gt;webdriver-&gt;get('http://127.0.0.1/testdir/'); // Here is the execute function $this-&gt;webdriver-&gt;execute('alert("Hello")', ''); $this-&gt;webdriver-&gt;get('http://127.0.0.1/testdir/'); // Here is the execute function $this-&gt;webdriver-&gt;execute('javascript:alert("Hello")', ''); $this-&gt;webdriver-&gt;get('http://localhost/testdir/'); // Here is the execute function $this-&gt;webdriver-&gt;execute('alert()', 'Hello'); } } </code></pre> <p>This is the function from The "WebDriver" class:</p> <pre><code>/** Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. * The executed script is assumed to be synchronous and the result of evaluating the script * is returned to the client. * @return Object result of evaluating the script is returned to the client. */ public function execute($script, $script_args) { $request = $this-&gt;requestURL . "/execute"; $session = $this-&gt;curlInit($request); $args = array('script' =&gt; $script, 'args' =&gt; $script_args); $jsonData = json_encode($args); $this-&gt;preparePOST($session, $jsonData); $response = curl_exec($session); return $this-&gt;extractValueFromJsonResponse($response); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload