Selenium and Phantomjs - PHP exec

116 views
Skip to first unread message

Marie Sutton

unread,
Apr 26, 2016, 10:19:16 AM4/26/16
to Selenium Users
I have Selenium working with Phantomjs on a Centos 7 server, BUT...only on the SSH/CLI. What I really want to do is run a Python script from PHP and get the resultant output.

When I use SSH command 'python myscript.py' it works properly.

When I run the PHP (which calls the python file using the exec method)in SSH 'php myphpfile.php' it also works properly.

However, when I try to run the php file in a browser (using the exec method) it quickly returns a blank page.

I have another php file using the exec method to call a python file (in the same directory),which works seamlessly. The difference is that this one does not use selenium (it uses Mechanize and BeautifulSoup). I have tried for hours to resolve this. Obviously there is some kind of problem between apache/and selenium but not apache and Mechanize et al.

I guess more simply it's that python is ok, but js is not since the browser access through php exec is fine when using python scripts.

I did read that via the web apache launches a process that has PHP in it. via command line there is no apache process. That's why I am traveling down that line....???

Still does not explain why I have success with php exec when there is no selenium/phantomjs involved. Any ideas/suggestions/fixes?

I do not have root access on SSH with my account

David

unread,
Apr 26, 2016, 7:55:09 PM4/26/16
to Selenium Users
What are you trying to do? Running Selenium to do some web processing over a web server is not optimal, even if using phantomjs.

And if you are using phantomjs, you might consider serving the content via node.js (express.js) rather than PHP as there is better/direct integration there being on the same language platform stack.

If you're using PHP on the web side, technically for some web queries you're making, you're better off using PHP curl to do the HTTP requests (GET, POST, etc.) rather than Selenium phantomjs or Mechanize, BeautifulSoup, and thus also bypass the Python script layer. PHP has JSON and XML parsing support itself as well.

If you prefer Python, then perhaps you should serve the content via a Python web framework instead of PHP (e.g. Bottle, Django).

Whatever you're doing can work as you've set up but it's too many layers to do something simple.

Boopathi ghfjh

unread,
May 2, 2016, 2:47:32 AM5/2/16
to Selenium Users
hi,

          i am boopathi. now i am manual tester  i want to move automation testing so please give some suggestion to learn selenium testing
Reply all
Reply to author
Forward
0 new messages