Having trouble with Selenium WebDriverJS on both FireFox and Internet Explorer

Having developed multiple JavaScript tests using chromedriver to run them in Chrome, I am now facing the challenge of running these same tests in FireFox and IE. The test below is functional in Chrome:

var assert = require('assert'),
test = require('selenium-webdriver/testing'),
webdriver = require('selenium-webdriver');


test.describe('Click current location button.', function () {
    test.it('Seems to have worked.', function () {
        var driver = new webdriver.Builder().
        withCapabilities(webdriver.Capabilities.chrome()).
        build();
        // Open Chrome (as specified by the Capabilities above) and go to the specified web page
        driver.get('website url').

        then(function () {

            driver.wait(function () {
                console.log("Looking for username");
                return driver.findElement(webdriver.By.id('user_username')).isDisplayed();
            }, 5000, 'Page did not load within 5 seconds');

            driver.findElement(webdriver.By.id("user_username")).sendKeys('user');
            driver.findElement(webdriver.By.id("user_password")).sendKeys('pword');

            return driver.findElement(webdriver.By.id("signIn")).click();
        }).
        then(function () {

            driver.sleep(4000);

            // make sure page has loaded        
            driver.wait(function () {
                console.log("Looking for current button");
                return driver.findElement(webdriver.By.id('gaz_input')).isDisplayed();
            }, 5000, 'Page did not load within 5 seconds');

            // Click Accept cookies to prevent issues 
            if (driver.findElement(webdriver.By.xpath("//a[@class='cc-cookie-accept']")).isDisplayed()) {
                driver.findElement(webdriver.By.xpath("//a[@class='cc-cookie-accept']")).click();
            }
            driver.sleep(1000);

            // Click the current location button
            driver.findElement(webdriver.By.xpath("//button[@class='btn']")).click();

            console.log("Looking for search results");
            driver.manage().timeouts().implicitlyWait(60000);

            if (!driver.findElement(webdriver.By.xpath("//div[@class='panel panel-default']")).isDisplayed()) {
                driver.wait(function () {                   
                    return driver.findElement(webdriver.By.xpath("//div[@class='panel panel-default']")).isDisplayed();
                }, 2000, 'Query did not complete within 60 seconds.');
            }

            driver.sleep(1000);
        }).
        then(function () {
            // Close the browser
            return driver.quit();
        });
    });
});

However, I am struggling to make it work on FF and IE. Changing the capabilities to firefox didn't yield the desired outcome. For IE, despite downloading the IEDriverServer and placing it in the same folder as the chromedriver, changing the driver capabilities to internetexplorer resulted in failed tests.

When attempting to run the test with internetexplorer capabilities, the following error occurred:

C:\Projects\build>mocha ietest.js
.
0 passing (42ms)
1 failing

1) Click current location button. Seems to have worked.:
 TypeError: Object function (opt_other) {

    /** @private {!Object} */
    this.caps_ = {};

    if (opt_other) {
        this.merge(opt_other);
    }
} has no method 'internetexplorer'
at Context.<anonymous> (C:\Projects\build\ietest.js:9:43)
...

Switching the capabilities to firefox produced a different error:

C:\Projects\build>mocha ietest.js
  .
  0 passing (1s)
  1 failing
1) Click MyNearest current location button. Seems to have worked.:
Error: ECONNREFUSED connect ECONNREFUSED
...

I've been stuck on this issue for some time now and would greatly appreciate any assistance. It could be a minor oversight on my part, but so far I haven't been able to resolve it.

Thank you, Anthony

Answer №1

For Firefox users, the WebDriverJs documentation provides a code example that can be found at https://code.google.com/p/selenium/wiki/WebDriverJs#Using_the_Stand-alone_Selenium_Server. To make it work, you'll need to install the Stand-alone Selenium Server and replace the pathToSeleniumJar in the code with the correct value.

As for Internet Explorer, a similar process is required:

var webdriver = require('selenium-webdriver'),
    SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;

var pathToSeleniumJar = 'C:\\selenium-2.41.0\\selenium-server-standalone-2.41.0.jar';

var server = new SeleniumServer(pathToSeleniumJar, {
  port: 4444
});

server.start();

var driver = new webdriver.Builder().
    usingServer(server.address()).
    withCapabilities(webdriver.Capabilities.ie()).
    build();

This setup should function properly since the IE Driver is likely already included in your system's path. Additional adjustments may be necessary, please refer to https://code.google.com/p/selenium/wiki/InternetExplorerDriver for any fine-tuning needed for your IE settings.

Answer №2

Although this question was asked some time ago, I wanted to share a solution for those who may be encountering the same issue.

If you are facing problems with the Selenium Server not starting, it could be causing your code execution issues. It's crucial to ensure that the Server is up and running before proceeding further.

function kickstartSeleniumServer(callback) {

   seleniumProcess = new SeleniumServer(path/to/selenium/server/jar, { port: 4444 });
   var promise = seleniumProcess.start();
   promise.then(function() {
      console.log("Selenium Server: Online");
      return callback();
   });
};

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

Retrieve data from a JSON gist by parsing it as a query string

I have a JavaScript-based application with three key files: index.html app.js input.json The app.js file references input.json multiple times to populate content in div elements within index.html. My goal is to enhance the functionality so that when acc ...

Validation in AngularJS is limited to only accepting integers with the use of the

Can you help me with validating positive integer numbers using the ng-pattern attribute? Currently, I have this pattern: ^[0-9]{1,7}(\.[0-9]+)?$/, but it also allows decimal values. I want to restrict it to only accept whole numbers. ...

What is the best way to hide only the rows in a table when it is clicked using JavaScript?

Is there a way to hide rows in these tables by clicking on the table head? I'm currently using bootstrap 5 so JQuery is not an option. <table class="table table-info table-bordered"> <thead id="tablea"> ...

The DOMException occurred when attempting to run the 'querySelector' function on the 'Document' object

Currently, I am engaged in a project that was initiated with bootstrap version 4.3.1. I have a keen interest in both JavaScript and HTML coding. <a class="dropdown-item" href="{{ route('user.panel') }}"> User panel </a& ...

Error message: Electron is unable to read properties of undefined, specifically the property 'receive'. Furthermore, the IPC is unable to receive arguments that were sent through an HTML iframe

I am currently working on passing light mode and language data from ipcMain to ipcRenderer via my preload script: Preload.js: const { contextBridge, ipcRenderer } = require("electron"); const ipc = { render: { send: ["mainMenuUpdate& ...

Create a table by incorporating the information from the page along with additional content

I need to extract the data from a list and convert it into a table, add some additional content that I will provide, and then align the table accordingly. While I can easily align elements and already have the list, I am facing difficulty in converting it ...

Retrieving Information from Ajax Call Using Python

I am struggling to figure out how to retrieve data from an Ajax request in my JavaScript code within a Python Flask application. The Ajax request I am working with does not involve jQuery. I have attempted using request.form.get() and request.get_json() i ...

Listen for the load event during an AJAX request without using jQuery's add

I have four HTML files and four corresponding JavaScript files. Each JavaScript file is externally loaded by its respective HTML file. Specifically, index.html loads javascript.js, 1.html loads javascript1.js, 2.html loads javascript2.js, and 3.html loads ...

Transform js into a more dynamic format to avoid redundancy when displaying items upon click

I came across a simple lightbox code snippet, but it's based on IDs and I plan to use it for more than 20 items. I don't want to manually write out 20 JavaScript lines when there could be a more efficient way to handle it dynamically. My JS skill ...

Creating an HTML table using an array of objects

I'm currently working on creating a function that will generate an HTML table from an array of objects. The array provided below is what I need to convert into a table. let units = [ { 'code': 'COMP2110', &apos ...

Is there a way to alter the text color using JavaScript on the client side?

Is there a way to change the color of a list item in a ul based on whether it is a palindrome or not? Here is the JavaScript file I am working with: function isPalindrome(text){ return text == text.split('').reverse().join(''); } c ...

Tips for extracting text from a text input field

Let's discuss a scenario involving an HTML text field. <input id="employeeId" class="formInputText" type="text" value="0013" name="employeeId" maxlength="10"/> The goal is to extract the content within the value="" attribute of the text box an ...

The $http.get request is successful only when the page is initially loaded for the first

Imagine this scenario: a user navigates to http://localhost:3000/all, and sees a list of all users displayed on the page. Everything looks good so far. However, upon refreshing the page, all content disappears and only raw JSON output from the server is sh ...

Angular: The Process of Completely Updating a Model Object

Within my application, there is an object named eventData which acts as a singleton and is injected into multiple controllers through a resolve function. This eventData contains various sets of data such as drop down list values along with the main model. ...

Manipulating arrays and troubleshooting Typescript errors in Vue JS

I am attempting to compare the elements in one list (list A) with another list (list B), and if there is a match, I want to change a property/field of the corresponding items in list B to a boolean value. Below is the code snippet: export default defineCo ...

Creating a custom arrow design for a select input field using CSS

I'm currently developing a website (using Wordpress with a custom theme) and I want to incorporate an up/down arrow in the select input field using CSS. The HTML code I have for creating the up/down arrow in the select input field is as follows: < ...

How can I send a value to an Angular element web component by clicking a button with JavaScript?

I want to update the value of an input in an Angular component by clicking on a button that is outside of the Angular Element. How can I achieve this in order to display the updated value in the UI? Sample HTML Code: <second-hello test="First Value"&g ...

Tips for utilizing a variable within a variable containing HTML code

Is it possible to incorporate variables in a JavaScript function that includes HTML code? Let's consider the following example: function SetCFonts() { var Color = $('#CColor').val(); var Font = $('#CFont').val(); var S ...

Error in Webdriver - Java Selenium Library

After spending a good amount of time working with Selenium, I've come across a frustrating issue. My automation keeps getting stuck at various points in the code and throws back a webdriver exception. I'm really struggling to figure out why this ...

The attempt to decode the string from POST using json_decode failed due to a hang-up in

I'm currently learning about PHP, JSON, and JavaScript. I am facing an issue with using the json_decode function in PHP after receiving a JSON string from JavaScript. I am able to save the JSON string to a file without any problem, but when I try to ...