Running selenium Java scripts in Linux Non-GUI servers with PhantomJs

45 views
Skip to first unread message

Suresh babu

unread,
Jul 12, 2018, 12:09:09 AM7/12/18
to Selenium Users
HI Team,

As of now iam using windows machine and developed some scripts and executed -- everything works fine in this scenario

but when i try to execute same scripts in Linux machine (Linux machine-- with out GUI only command line we have) scripts are not executing.

Procedure followed to execute scripts in linux machine:

1. Maintained all jars(TestNG and Selenium Stand alone) in lib folder 
2. I have used Phantom JS which is used for Headless browser for testing

Sample java code but not the exact app elements:

               File file = new File("path of pahntomjs driver");
System.setProperty("phantomjs.binary.path", file.getAbsolutePath());
WebDriver driver = new PhantomJSDriver();
driver.manage().window().setSize(new Dimension(1400,1000));
driver.get("https://www.google.com/");
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.findElement(By.xpath("//*[@id="lst-ib"]")).sendKeys("Test");
driver.findElement(By.name("btnK")).click();
Thread.sleep(3000);
driver.close();

Note: Executed above scripts in windows it worked fine but where as in Linux command line it is not executing and getting below error.

Error message: errorMessage":"Unable to find element with xpath '//input[@id='pt1:_pt_it1::content']'"



Executed below lines of statements in putty (command linux server):

javac -classpath "/tmp/SeleniumUsecases/lib/*" -d ./bin ./src/Testcases/*.java
java -classpath /tmp/SeleniumUsecases/lib/*:/tmp/SeleniumUsecases/bin org.testng.TestNG /tmp/SeleniumUsecases/testng.xml 


Please provide any inputs on this

Thanks in Advance.

Shawn McCarthy

unread,
Jul 14, 2018, 5:23:37 PM7/14/18
to Selenium Users
Why are you using phantomjs ? I believe it is deprecated, since firefox and chrome both have --headless flags.

Suresh babu

unread,
Jul 14, 2018, 6:09:33 PM7/14/18
to Selenium Users
I have tried with chrome but when I compile and run the program getting this error ‘GLIBC_2.4 not found’

Tried to set GLIBC issue but after that it’s not getting compiled only and system is getting hanged

my current system configuration is “CENTOS 6” command terminal (might be it is not supporting chrome)

Hence using phantomJs here that driver itself not recognising

Please let me know if you have any inputs to overcome this issue

Regards,
Suresh.

Serguei Kouzmine

unread,
Jul 21, 2018, 12:09:45 AM7/21/18
to Selenium Users
Hello Babu
 
The code snippet provided in the question appears very basic. Try adding taking screnshots and a few assertions against page url, page contents, search  for some other elements to narrow down the problem to an invalid locator or inability to run the app   or something else,
   BTW You can sure try the phantomjs on windows to narrrow it down even further. 

Sorry to hear about the problem with glibc.  You sure can try it with headless Firefox, it may not need that particular version

Thanks

Serguei Kouzmine
Reply all
Reply to author
Forward
0 new messages