How to run test scripts in Selenium using PhantomJS?

0 votes
Please anyone suggest how to run test scripts in Selenium using PhantomJS?
3 days ago in Selenium by Shushil
8 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Hey @Shushil, you can run your test scripts using PhantomJS browser in Selenium with following code snippet:

package headlessDriver;
import java.io.File;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.phantomjs.PhantomJSDriver; 

public class PhantomDriver {   
  public static void main(String[] args) {
                 File file = new File("C:/Program Files/phantomjs-2.0.0-windows/bin/phantomjs.exe");   
                    System.setProperty("phantomjs.binary.path", file.getAbsolutePath()); 
                    WebDriver driver = new PhantomJSDriver();
                    driver.get("http://www.google.com");        
                    WebElement element = driver.findElement(By.name("q"));
                    element.sendKeys("Edureka");    
                    element.submit();           
                    System.out.println("Page title is: " + driver.getTitle()); 
                    driver.quit();  
           } 
}

Once you run this code, you will observe the output is shown in your Console and no browser is launched:

answered 2 days ago by Abha
• 5,480 points

Related Questions In Selenium

0 votes
1 answer

Can anyone help me that how to run Selenium WebDriver test cases in Chrome?

Download the executable driver from: ChromeDriver Download Before ...READ MORE

answered Mar 29, 2018 in Selenium by nsv999
• 5,030 points
116 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,030 points
1,200 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,030 points
52 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
415 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
40 views
0 votes
1 answer

How to read a JS variable in Selenium Webdriver?

Hi Himanshu, its quite easy to access any ...READ MORE

answered May 7 in Selenium by Abha
• 5,480 points
11 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.