Selenium -Java Chrome driver issue Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created: cannot connect to chrome at 127.0.0.1:9111 from chrome not reachable
akhilcharugulla opened this issue · 2 comments
I am trying to use the same chrome version and chrome driver version "127.0.0.1:9111"
image
Chrome driver is downloaded from this link: https://storage.googleapis.com/chrome-for-testing-public/127.0.6533.100/win64/chromedriver-win64.zip
Error I get:
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created: cannot connect to chrome at 127.0.0.1:9111
from chrome not reachable
Host info: host: 'DESKTOP-KJRP5I8', ip: '192.168.56.1'
Build info: version: '4.23.0', revision: '4df0a231af'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '22.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [], debuggerAddress: 127.0.0.1:9111, extensions: []}}]}]
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:114)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:75)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:61)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:162)
at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:216)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:174)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:234)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:163)
at org.openqa.selenium.chromium.ChromiumDriver.(ChromiumDriver.java:114)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:88)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:83)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:72)
at org.example.ExcelToGoogleSearch.main(ExcelToGoogleSearch.java:31)
I am trying to run the chrome in remote debugging mode
chrome.exe --remote-debugging-port=9111 --user-data-dir="C:\Users\User\AppData\Local\Google\Chrome\User Data"
My code to access the manually opened browser:
package org.example;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public static void main(String[] args) {
String excelFilePath = "C://Users//User//Downloads//FY24-H1B-Information-IT-Companies.xlsx";
int startRow = 5;
int endRow = startRow + 10;
int columnNumber = 2; //company name is in the third column
List companyNames = readExcelCells(excelFilePath, 0, startRow, endRow, columnNumber);
if (!companyNames.isEmpty()) {
WebDriverManager.chromedriver().clearDriverCache().setup();
System.setProperty("webdriver.chrome.driver", "C://Users//User//Downloads//chromedriver-win64//chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("debuggerAddress", "127.0.0.1:9111");
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.google.com");
for (String companyName : companyNames) {
searchInNewTab(driver, companyName);
}
} else {
System.out.println("Failed to read the cell contents.");
}
}
private static List readExcelCells(String filePath, int sheetNumber, int startRow, int endRow, int columnNumber) {
List cellContents = new ArrayList<>();
try (FileInputStream fis = new FileInputStream(filePath);
Workbook workbook = new XSSFWorkbook(fis)) {
Sheet sheet = workbook.getSheetAt(sheetNumber);
for (int rowNumber = startRow; rowNumber <= endRow; rowNumber++) {
Row row = sheet.getRow(rowNumber);
if (row != null) {
Cell cell = row.getCell(columnNumber);
if (cell != null) {
cellContents.add(cell.toString());
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
return cellContents;
}
private static void searchInNewTab(WebDriver driver, String companyName) {
// Open a new tab
((JavascriptExecutor) driver).executeScript("window.open('about:blank','_blank');");
// Switch to the new tab
ArrayList tabs = new ArrayList<>(driver.getWindowHandles());
driver.switchTo().window(tabs.get(tabs.size() - 1));
// Perform the search
driver.get("https://www.google.com");
driver.findElement(By.name("q")).sendKeys(companyName);
driver.findElement(By.name("q")).submit();
}
}
This line should not be required:
System.setProperty("webdriver.chrome.driver", "C://Users//User//Downloads//chromedriver-win64//chromedriver.exe");
In any case, this seems not a WebDriverManager problem.
@bonigarcia can you please share me an active repo ,so I can post this issue and get some help