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
1,744 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
• 28,140 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
• 28,140 points
1,968 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
4,142 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,500 points
13,673 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,142 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,910 points
7,221 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 3, 2020 in Selenium by Sri
• 3,190 points
7,874 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
• 28,140 points
2,927 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP