How to run test scripts in Selenium using PhantomJS?

0 votes
Please anyone suggest how to run test scripts in Selenium using PhantomJS?
May 17, 2019 in Selenium by Shushil
402 views

1 answer to this question.

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 May 17, 2019 by Abha
• 27,930 points

Related Questions In Selenium

0 votes
2 answers

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

You first need to download chrome driver ...READ MORE

answered Aug 26, 2019 in Selenium by Abha
• 27,930 points
718 views
0 votes
1 answer
0 votes
1 answer

How to run Selenium test cases in Headless Chrome browser?

@Afreen to run selenium test cases in ...READ MORE

answered May 17, 2019 in Selenium by Kushal
1,911 views
0 votes
1 answer
0 votes
2 answers

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,510 points
3,536 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,542 views
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,890 points
2,599 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
2,865 views
0 votes
1 answer
0 votes
1 answer

How to run a group of test cases using TestNG in Selenium Webdriver?

Hey Kajal, TestNG allows you to perform ordered ...READ MORE

answered Jun 12, 2019 in Selenium by Abha
• 27,930 points
1,096 views