Establish a connection with an existing web driver using Selenium in JavaScript

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.

Answer №1

A solution is to update your Chrome driver to version 77, as the latest version of Selenium (3.141.59) does not support other versions of Chrome. Visit this link (https://www.seleniumhq.org/download/) to download the latest chromedriver.exe and resolve the issue.

Answer №2

An issue has occurred - SessionNotCreatedError: session not created: This version of ChromeDriver only supports Chrome version 77

This error is due to a mismatch between the chromedriver.exe and the version of the Chrome browser installed on the operating system. To resolve this, you can download the appropriate chromedriver.exe based on the browser version from the following link https://chromedriver.chromium.org/downloads

Solution for the question - Yes, it is possible to establish a connection with an existing running selenium server by configuring desired capabilities via chrome. These capabilities can be passed while initializing the selenium session

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

The main task now is to find the equivalent javascript code to achieve the same functionality as demonstrated above using java bindings with selenium. I will update this answer once I find the js binding.

@Edit=> I managed to figure out how to pass chrome options in javascript. However, the setExperimentalOptions method was not available in ChromeOptions library. In its place, I utilized the addArguments method as illustrated 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');

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Align the date input field to the center for better visual appeal

I am facing a challenge in centering the date in an input, not the entire input element inside a div. When I attempt to center it, the date gets positioned within a portion of the input due to a resizable right-hand side panel for selecting a date from a c ...

What is the best way to determine which option is most suitable: types, classes, or function types in TypeScript for

Currently, I am developing a small todo command line utility with a straightforward program structure. The main file is responsible for parsing the command line arguments and executing actions such as adding or deleting tasks based on the input provided. E ...

Buttons to maximize, minimize, and close individual sections on a webpage

I am fairly new to front end development and I must say, I am absolutely enjoying every bit of it. Here is a little challenge that came my way. It may seem simple to some but it got me thinking. I have three sections on the right side of my website. I wa ...

Update AngularJS data models using the callback function "on change" from a jQuery plugin

Currently, I am in the process of developing a web application for a touchscreen computer that requires an on-screen keyboard. After searching extensively, I came across this fantastic (or at least the best one I could find) keyboard plugin: https://github ...

The final thumbnail fails to appear in the visible display (react-responsive-carousel)

I am currently facing an issue with displaying a series of images using react-responsive-carousel. When the images exceed a certain size causing the thumbnail section to become scrollable, the last thumbnail is always out of view. Although I have impleme ...

Analyzing a server's log data at regular intervals

Currently, I am working on a project where I need to parse a server log file using JavaScript every 24 hours and then store the extracted information in a MongoDB database. The process of parsing the data and storing it is what I find to be the most chall ...

Encountering issues with the find_element_by_id() method in Selenium WebDriver using Python and PhantomJS

Having trouble with web test cases in Python using Selenium WebDriver and PhantomJS. Getting an error on driver.find_element_by_id("username"). Here is the relevant HTML: <input class="form-control" name="username" id="username" type="text" placeholde ...

Failure to Load Options into Select Dropdown Using jQuery

Attempting to fetch select options from a JSON using jquery. Below is the html form code (with search options) - <div class="form-group row"> <label for="" class="col-sm-2 form-control-label">Country</label> <div class="col-sm ...

Is it true that Safari restricts AJAX Requests following a form submission?

I've developed a JavaScript-based upload progress meter that utilizes the standard multipart submit method instead of submitting files in an iframe. The process involves sending AJAX requests during submission to retrieve the percentage complete of th ...

I found myself unable to execute a query with varying conditions using mongoose

These are my Operator Models: const operatorSchema = new Schema({ operatorName: { type: String }, users:[{ email:String, payment:Number, paymentsData: Date, product: String, }], }); I am lookin ...

Stop all threads without causing them to wait

I am currently facing a challenge in building a bot using selenium. The issue arises when the website unexpectedly logs me out without any prior warning. Although I am familiar with how to detect and handle this issue, it becomes unreasonable to constantly ...

Display each new array element on a separate line

let team = [['Sara', 'John', 'Kate']] let newTeam = team.map(function(r) { return r; }) outputs [ [ 'Sara', 'John', 'Kate' ] ] Is there a way to modify it so that each value is r ...

Obtaining the Maximum Amount and Corresponding Bank Name using Selenium

When working with a web table in a web application, one column is labeled Bank and another is labeled Amount. I need to extract the bank name along with the highest amount from the table using Selenium. What approach can be used to achieve this? ...

[Vue alert]: Issue with rendering: "Sorry, unable to read property 'correct_answer' as it is undefined"

My code fetches data from an API. The questions display correctly, but the answers cause an error that crashes the app. Initially, the code worked fine in App.vue, but moving it to a different view page caused the crash. Any suggestions on how to fix this ...

Can JavaScript and CSS be used to dynamically style textarea content as it is being typed by the user?

I am wondering if it is possible to apply styling to content in a textarea as a user inputs text. For instance: <textarea>abcdefghijklmnopqrstuvwxyz</textarea> Is there a way to highlight all the vowels in the textarea string above using jav ...

Displaying a group of elements in ReactJS

I'm currently working on assembling an array using different JSX components. There's a function I've created that populates this array with components and then returns it. let components = []; switch (obj.type) { case 'title': ...

Using Jquery to add text at the beginning of a Gmail signature

I am currently working on creating a tool using InboxSDK, which adds text to the end of an email message just before the signature. InboxSDK provides the message body as an HTML Element, and I am experimenting with using Jquery to insert the text. The chal ...

Tips for fixing the issue: Absence of the environment variable 'TWITTER_CONSUMER_KEY'

Being a novice in programming, I didn't anticipate encountering errors so soon. Today, I attempted to code a Node.js application for posting Twitter Feeds to Discord but faced failure. I'm puzzled as to why this error is occurring even though I& ...

Assigning index values to child rows in AngularJS: a step by step guide

One of my requirements involves assigning index values to child rows. The structure includes group rows with child rows underneath. Currently, I am using ng-repeat along with $index for the children as shown below: HTML code: <table ng-repeat="nod ...

I'm currently facing an issue with toggling the visibility of a div using JavaScript

In my attempt to create a unique custom select menu using html, css, and javascript, I encountered an issue with toggling the display style of the div containing the options when clicking on the button (in this case, an arrow). HTML: <ul class="de ...