Selenium WebDriver Cheat Sheet – Advanced Topic- Firefox/Chrome Profiling

Posted by

Cheat Sheets are the most effective way to teach things to others, there is an acute shortage of Selenium WebDriver Cheat Sheets, so we have decided to create one yourself for you guys. This cheat sheet for selenium WebDriver provides all the important and commonly used methods, operations and commands for your easy daily access.

  1. package firefoxprofile;
  2. import org.openqa.selenium.WebDriver;
  3. import org.openqa.selenium.chrome.ChromeOptions;
  4. import org.openqa.selenium.firefox.FirefoxDriver;
  5. import org.openqa.selenium.firefox.FirefoxProfile;
  6. import org.openqa.selenium.remote.DesiredCapabilities;
  7. import org.openqa.selenium.remote.RemoteWebDriver;
  8. import com.gargoylesoftware.htmlunit.javascript.host.file.File;
  9. public class firefoxprofile
  10. {
  11.        public static void main(String[] args)
  12.        {
  13.               //Load firefox from non default location
  14.               System.setProperty(“webdriver.firefox.bin”, “mentioned path here”);
  15.               FirefoxProfile fp = new FirefoxProfile();
  16.                /*
  17.                * //load firefox with addons if you want with
  18.                *
  19.                * File file = new File(“path/to/extension.xpi”);
  20.                * fp.addExtension(file);
  21.                *
  22.                */
  23. DesiredCapabilities dc = new DesiredCapabilities();

  24.               dc.setCapability(FirefoxDriver.PROFILE, fp);
  25.               WebDriver driver = new RemoteWebDriver(dc);
  26.               driver.close();
  27.               //For other setting of browser profile of Chrome

  28.               ChromeOptions options = new ChromeOptions();
  29.               DesiredCapabilities dc01 = new DesiredCapabilities();
  30.               dc01.setCapability(ChromeOptions.CAPABILITY, options);
  31.               WebDriver driver01 = new RemoteWebDriver(dc01);
  32.               driver01.close();
  33.        }
  34. }

Leave a Reply

Your email address will not be published. Required fields are marked *