Tomi
Tomi

Reputation: 3560

Connect to already started web driver with selenium js

I'm not an expert of Selenium, so I may miss something here.

I know the port where the ChromeDriver starts:

Starting ChromeDriver 77.0.3865.10 (bc3579f611bbc73331171afe020ec7a45e6ccc55-refs/branch-heads/3865@{#93}) on port 55848

I try to connect from JS:

const webdriver = require('selenium-webdriver')

void async function() {
    let driver = await new webdriver.Builder().forBrowser('chrome').usingServer('http://localhost:55848/').build();

    await driver.get('http://www.google.com/ncr');
    await driver.findElement(By.name('q')).sendKeys('webdriver');
    await driver.findElement(By.name('btnG')).click();
    await driver.wait(until.titleIs('webdriver - Google Search'), 1000);

    driver.quit();
}();

The connection is not successful. What I can think is that this code tries to start a new instance.

There is an error message:

SessionNotCreatedError: session not created: This version of ChromeDriver only supports Chrome version 77

I checked that the running chrome version is 77 and the ChromeDriver is also 77. This Chrome that is started by the corp software is actually a portable version of Chrome. I have a Chrome 76 installed on my computer. What I can think is that the code I wrote tries to start a new instance of Chrome. And there the version does not match.

Any idea how I can connect to the existing one? And control it?

UPDATE:

I managed to do the same with Firefox. The Firefox is started with geckodriver. I still cannot connect it. The error message is:

SessionNotCreatedError: Session is already started

So I'm pretty sure that is not in connection with the chrome versions but it tries to create a new session instead of connecting the existing one.

Upvotes: 4

Views: 2210

Answers (2)

Amit Jain
Amit Jain

Reputation: 4587

Error - SessionNotCreatedError: session not created: This version of ChromeDriver only supports Chrome version 77

The error is related to mismatch between chromedriver.exe and chromebrowser version. So based on browser version installed in operating system we have, we can download chromedriver.exe from below link https://chromedriver.chromium.org/downloads

Actual question answer - Yes, we can connect to an existing running selenium server by setting desired capabilities provided by chrome. Then passing this capability while creating selenium session

ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("debuggerAddress", "77.0.3865.10:55848");
WebDriver driver = new ChromeDriver(options);

The only thing to be searched is equivalent javascript code for doing same as above code is using java binding with selenium. I will surely update this answer with js binding.

@Edit=> This is something I was able to find the way to pass chrome options in javascript. But sadly I didn't found setExperimentalOptions method here inside ChromeOptions. So I have used addArguments method as shown below.

const { Options } = require('selenium-webdriver/chrome');
const options = new Options();
options.addArguments('debuggerAddress=77.0.3865.10:55848');
builder.setChromeOptions(options);
const driver = builder.build();
driver.get('url');

Upvotes: 1

Pratik
Pratik

Reputation: 357

Yes, the problem is with the version of chrome driver. Get chromedriver.exe version 77... or else you will keep getting this error as latest version of selenium 3.141.59 doesnt support other version of chrome. Go to this link (https://www.seleniumhq.org/download/) and get the chromedriver.exe latest version and I think it will solve your problem.

Upvotes: 1

Related Questions