0

Below is my code but it gives me null point error. some please help me out to find out what is the error

package path1;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;

public class New1 {
  public static void main(String[] args) {          
    System.setProperty("webdriv`enter code here`er.gecko.driver", "C://Users/Ramesh/Desktop/Udemy/Selenium/geckodriver.exe");      
    ProfilesIni profile = new ProfilesIni();

    FirefoxProfile testprofile = profile.getProfile("default");
    testprofile.setAcceptUntrustedCertificates(true);
    testprofile.setAssumeUntrustedCertificateIssuer(true);

    WebDriver driver = new FirefoxDriver(testprofile);
    driver.get("https://www.w3schools.com/");
  }    
}
Jeroen Heier
  • 3,520
  • 15
  • 31
  • 32

2 Answers2

0

It is because of this line:

     FirefoxProfile testprofile = profile.getProfile("default");

Ýou can't get that specific profile. Try checking your profiles and make a change there. Also your setup is wrong. Change your first line with this:

 System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver.exe");
strash
  • 1,291
  • 2
  • 15
  • 29
-1

Here are some key points you need to address:

  1. System.setProperty - you need to properly mention webdriver.gecko.driver
  2. FirefoxProfile testprofile = profile.getProfile("default"): It is worth mentioning that the default Firefox profile is not very automation friendly. When you want to run automation reliably on a Firefox browser it is advisable to make a separate profile. Automation profile should be light to load and have special proxy and other settings to run good test. You should be consistent with the profile you use on all development and test execution machines. If you used different profiles everywhere, the SSL certificates you accepted or the plug-ins you installed would be different and that would make the tests behave differently on the machines.

    • There are several times when you need something special in your profile to make test execution reliable. The most common example is a SSL certificate settings or browser plug-ins that handles self-signed certs. It makes a lot of sense to create a profile that handles these special test needs and packaging and deploying it along with the test execution code.
    • You should use a very lightweight profile with just the settings and plug-ins you need for the execution. Each time Selenium starts a new session driving a Firefox instance, it copies the entire profile in some temporary directory and if the profile is big, it makes it, not only slow but unreliable as well.
    • Create a New Firefox profile and use the same in the Test script involves three steps process. First you need to Start the Profile Manager, second is to Create a New Profile and third is to use the same profile in Test scripts. Let's assume we created a new FirefoxProfile by the name "debanjan".
  3. Use the following code to open https://www.w3schools.com/ with your new FirefoxProfile "debanjan":

    System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe");
    ProfilesIni profile = new ProfilesIni();
    FirefoxProfile testprofile = profile.getProfile("debanjan");
    testprofile.setAcceptUntrustedCertificates(true);
    testprofile.setAssumeUntrustedCertificateIssuer(true);
    WebDriver driver = new FirefoxDriver(testprofile);
    driver.get("https://www.w3schools.com/");
    
honk
  • 9,137
  • 11
  • 75
  • 83
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352