Prashanth Sams
Prashanth Sams

Reputation: 21129

Unable to Launch Google Chrome using default/custom profile in Selenium WebDriver that undergo http basic authentication

Following methods are not working properly. Since GRID is used, capability is set as null here.

System.setProperty("webdriver.chrome.driver", "C:/chromedriver.exe");   
DesiredCapabilities capability=null; 

Method 1:

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--user-data-dir=C:/Users   /username/AppData/Local/Google/Chrome/User Data/Default"));
driver = new ChromeDriver(capabilities);

Method 2:

DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 
String chromeProfile = "C:/Users/username/AppData/Local/Google/Chrome/Application   /chrome.exe"; 
ArrayList<String> switches = new ArrayList<String>(); 
switches.add("C:/Users/username/AppData/Local/Google/Chrome/User Data/Default" + chromeProfile); 
capabilities.setCapability("chrome.switches", switches); 
driver = new ChromeDriver(capabilities); 

Upvotes: 2

Views: 5394

Answers (2)

Prashanth Sams
Prashanth Sams

Reputation: 21129

System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=C:/Users/user_name/AppData/Local/Google/Chrome/User Data");
options.addArguments("--start-maximized");
driver = new ChromeDriver(options);

If you face such error:

org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited normally

Then try to create a new Chrome profile and execute tests.

  1. Copy the folder, 'User Data'
  2. Paste & Rename the folder on the same location. e.g., New User
  3. Now, locate the directory, C:/Users/user_name/AppData/Local/Google/Chrome/New User
  4. If you like to test the profile, then bookmark some of the sites & observe them on next run.

Upvotes: 2

Pavel Janicek
Pavel Janicek

Reputation: 14738

1 Set the chromedriver property in starting the node. My approach:

java -jar selenium-server-standalone-2.31.0.jar -role node -hub http://localhost:4444/grid/register -maxSession 15 -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=15 -Dwebdriver.chrome.driver=lib\chromedriver.exe

2 Inside the code my approach:

capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"));
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), capabilities);

3 loading the HTTP basic auth page:

String username = "Pavel";
String password = "Omgtoosecrettotellyou";
driver.get("http://" + username + ":" + password + "@" +"your-site.com");

Upvotes: 0

Related Questions