While I don't claim to be a Selenium expert, there may be something important that I'm overlooking in this situation.
- One of the software within the company initiates Google Chrome using ChromeDriver.
- I aim to link up with this browser through my JavaScript code.
I have knowledge of the port where ChromeDriver initiates:
Starting ChromeDriver 77.0.3865.10 (bc3579f611bbc73331171afe020ec7a45e6ccc55-refs/branch-heads/3865@{#93}) on port 55848
In my attempt 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();
}();
Unfortunately, the connection was unsuccessful. My assumption is that this code attempts to start a new instance.
An error message appears:
SessionNotCreatedError: session not created: This version of ChromeDriver only supports Chrome version 77
Upon checking, I confirmed that both the running chrome version and ChromeDriver are at version 77. The Chrome launched by the corporate software happens to be a portable version. However, I have Chrome 76 installed on my computer. It seems like the code I've written tries to initiate a fresh Chrome instance, resulting in a version mismatch.
Any suggestions on how I can establish a connection with and manage the existing one?
UPDATE:
I attempted the same procedure with Firefox, which is initiated using geckodriver. Still unable to establish a connection. An error message reads:
SessionNotCreatedError: Session is already started
Hence, I believe it's not related to the Chrome versions; rather, the script probably creates a new session instead of linking to an existing one.