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 in Selenium by Shushil
46 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 by Abha
• 23,030 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 in Selenium by Abha
• 23,030 points
252 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
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,090 points
592 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
901 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
579 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 in Selenium by Abha
• 23,030 points
78 views