We can do browser specific setting in selenium using ProfileIni, FirefoxProfile and FirefoxOptions class if we want it for firefox.
>To specify download folder we can specify folder dir.
FirefoxProfile prof = new FirefoxProfile();
prof.setPreference("browser.download.folderList",2);
prof.setPreference("browser.download.dir", "C:\\GAURAV\\Downloads\\");
FirefoxOptions option = new FirefoxOptions();
option.setProfile(prof);
>To add home page we can specify browser.startup.homepage attribute
FirefoxProfile prof = new FirefoxProfile();
prof.setPreference("browser.startup.homepage", "https://www.kiet.edu/");
FirefoxOptions option = new FirefoxOptions();
option.setProfile(prof);
>For localisation we can specify language code
FirefoxProfile prof = new FirefoxProfile();
prof.setPreference("intl.accept_languages", "hin");
>For creating customized profile first press win+r and give firefox.exe -p , it is going to launch a popup where you have to click on create new (suppose you give name of new profile as 'Custom') and then click on start firefox. Now you have to do settings which you want to have in your browser and close the browser, and then you can call this in your code.
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("Custom");
FirefoxOptions option = new FirefoxOptions();
option.setProfile(myprofile);
WebDriver driver = new FirefoxDriver(option);
If we want to perform browser settings in chrome then we can achive it using hashmap and chrome options class.
For details refer this video
>To specify download folder we can specify folder dir.
FirefoxProfile prof = new FirefoxProfile();
prof.setPreference("browser.download.folderList",2);
prof.setPreference("browser.download.dir", "C:\\GAURAV\\Downloads\\");
FirefoxOptions option = new FirefoxOptions();
option.setProfile(prof);
>To add home page we can specify browser.startup.homepage attribute
FirefoxProfile prof = new FirefoxProfile();
prof.setPreference("browser.startup.homepage", "https://www.kiet.edu/");
FirefoxOptions option = new FirefoxOptions();
option.setProfile(prof);
>For localisation we can specify language code
FirefoxProfile prof = new FirefoxProfile();
prof.setPreference("intl.accept_languages", "hin");
>For creating customized profile first press win+r and give firefox.exe -p , it is going to launch a popup where you have to click on create new (suppose you give name of new profile as 'Custom') and then click on start firefox. Now you have to do settings which you want to have in your browser and close the browser, and then you can call this in your code.
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("Custom");
FirefoxOptions option = new FirefoxOptions();
option.setProfile(myprofile);
WebDriver driver = new FirefoxDriver(option);
If we want to perform browser settings in chrome then we can achive it using hashmap and chrome options class.
Reference Links:
https://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/pref_names.cc?view=markup
http://kb.mozillazine.org/About:config_entries
https://peter.sh/experiments/chromium-command-line-switches/
https://chromium.googlesource.com/chromium/src/+/master/chrome/common/pref_names.cc
https://stackoverflow.com/questions/38335671/selenium-chrome-where-can-i-find-a-list-of-all-available-chromeoption-arguments
Save Water | Save Energy | Save Earth
Stop Pollution | Stop Plastic
Spread Peace
No comments:
Post a Comment