What is the process of emphasizing a WebElement in WebdriverIO?

Is there a way to highlight web elements that need to be interacted with or asserted in webdriverIO? Or is there a JavaScript code similar to the javascript executor in Selenium that can be used for this purpose?

Answer №1

If you want to bring attention to a specific web element, there is a method to highlight it. This process is explained here:

'use strict';

var _ = require('underscore');
var async = require('async');

var highlight = function (elements, callback) {

    if (!window.jQuery) {
        return callback();
    }

    var unhighlightable = [
        ':checkbox',
        ':radio'
    ];

    var $element = window.jQuery(elements).first();

    for (var i = 0, l = unhighlightable.length; i < l; i++) {

        if ($element.is(unhighlightable[i])) {
            $element = $element.parent();
            break;
        }
    }

    var restore = {
        backgroundColor: $element.css('backgroundColor')
    };

    $element.animate({
        backgroundColor: '#ffff00'
    }, 200, function () {
        $element.delay(100).animate(restore, 200, callback);
    });
};

/**
 * To ensure that an element, selected by CSS or XPath selector, is highlighted using jQuery after a certain
 * number of milliseconds, use this command. If the selector matches multiple elements,
 * only the first one will be animated. In case jQuery is not present in the system, no action will be taken.
 * @param {String} selector Selector that matches elements to be highlighted
 */
module.exports = function (selector) {

    // Check that the callback includes chainit callback
    var callback = _.last(arguments);

    if (!_.isString(selector)) {
        return callback(new Error('Number or type of arguments do not agree with "highlight" command.'));
    }

    var self = this;
    var timeout = 5000;
    var payload = {};

    async.waterfall([

        function (callback) {
            self.timeoutsAsyncScript(timeout, callback);
        },

        function (response, callback) {
            payload.timeoutsAsyncScript = response;
            self.moveToObject(selector, callback);
        },

        function (value, response, callback) {
            payload.moveToObject = response;
            self.selectorExecuteAsync(selector, highlight, callback);
        }

    ], function (error, value, response) {
        payload.selectorExecuteAsync = response;
        callback(error, payload);
    });
};

Following that:

  this.client.addCommand('highlight', require('./path/to/above/module'));
  this.client.highlight('#element').click('#element');

or:

// not tested
module.exports = function (selector) {
    var callback = _.last(arguments);
    async.waterfall([
        this.highlight.bind(this, selector), 
        this.click.bind(this, selector)
    ], callback);
}

// later on...
this.client.addCommand('press', require('path/to/module/that/highlights/and/clicks'));
// later on..
this.client.press('#element');

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

Two sets of buttons, however, one set is carrying out the incorrect function

I am trying to create two button sets that, when clicked, are supposed to angle the text below them at 45 degrees. However, I am facing an issue where both set 1 and set 2 only control the text linked to button 1. I need each button set to control their ...

Currently, I'm attempting to execute npm run dev as I install the authentication user interface within Laravel

Error: Module 'F:\vite\bin\vite.js' Not Found at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15) at Function.Module._load (node:internal/modules/cjs/loader:769:27) at Function.executeUserEntry ...

Is it feasible to directly load image objects into jQuery colorbox?

Currently, I am working with the "colorbox" jQuery plugin and I have a specific requirement to dynamically load a set of preloaded image objects into colorbox. The challenge lies in the fact that I have three different image sizes - thumbnail, display, an ...

Obtain the Xpath for the element with a certain tag located closest to the given element in its immediate surrounding

Within my HTML document, I have a specific element with an id of uniqueId. There are multiple nested tags surrounding this element, and I am trying to retrieve a particular tag that is closest to it. For example: <div> <div> ...

Animation of active chat list items on Whatsapp

Has anyone figured out a simple method to create an animation like the one in Whatsapp? For example, when you are on a chat screen and go back to the chat list, have you noticed how an active element is briefly highlighted in gray (to indicate which chat ...

Various SVG paths make up segments

I have created an intricate SVG file containing 35 different paths resembling train tracks. My next step is to break down these paths into 16 segments, allowing another SVG path (train) to smoothly traverse along them. The ultimate goal is to grant users ...

How can you set up automatic publishing for npm packages?

Seeking advice on organizing NPM packages autopublishing with TeamCity. There are multiple NPM packages housed within a single git repository. The goal is to automatically detect any changes made to the packages, update their version, create a new commit ...

What are the steps to store a firebase storage downloadURL in a firestore collection?

I'm facing an issue with saving my firebase storage image into a firestore collection variable. Initially, it was working correctly but suddenly stopped functioning, and now the image variable is returning null. Note: I am using the asia-south1 serve ...

Exploring the Contrast between window.location.href and top.location.href

I'm curious about the distinction between window.location.href and top.location.href. Can anyone explain this to me? Furthermore, I'd like to know when it's appropriate to use each one. Which option is more suitable for redirection after a ...

Ways to avoid overflow of dynamically added div element?

Currently, I am facing an issue while dynamically appending div elements with the .magnet class to my page. These elements end up overflowing the container boundaries and I am struggling to find a solution for this problem. If anyone could check out my j ...

The attempt to run 'readAsBinaryString' on 'FileReader' was unsuccessful. The first parameter is not the expected type 'Blob'

I am currently working on parsing an xls file. You can find the file by clicking on the following link: However, I am encountering an error that says: 'Failed to execute 'readAsBinaryString' on 'FileReader': parameter 1 is not of ...

Is there a way to prevent npm (version 5.3.0) from auto-deleting local modules when I install or uninstall packages?

Recently, I updated my npm to version 5.3.0 and encountered an issue. Every time I install or uninstall a module, npm automatically deletes the local modules I personally added to my node_modules directory. These local modules are not listed in my packag ...

Is there a way to retrieve an HTML file from a different directory using Express?

I am currently utilizing an HTML file in the same folder. How can I access an HTML file saved in a different folder using express? Thank you. const express=require('express') const path=require('path') const app=express() app.get(& ...

Ways to disable the ability to close a bootstrap modal by pressing the backspace key

How can I enable the backspace button in a Bootstrap Modal form for textboxes and textareas? $('body').keydown(function (e) { if ($('#myModal').is(':visible')) { if (e.keyCode == 8) { retu ...

Setting up sockets.io with npm on our Vagrant environment

Upon executing the command in my Unix Vagrant box, sudo npm install -g socket.io, I receive the following response after a few seconds: > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e39490a3d3cdd7cdd0d2">[email p ...

Learning how to integrate Next.js, React.js, and Redux into an HTML page for an enhanced user

My current project is built on Asp.Net MVC, but the technology used is not crucial. I integrated react.js and redux for searching a section of my html page using a cdn link. Now, I am considering deploying the server side of the application with next.js. ...

Efficiently converting HTML object data into plain text using RegExr in ReactJS and JavaScript

Is there a way to convert an object in JavaScript/ReactJS into a string? For instance, consider the following object: { article: '<p class="md-block-unstyled">First text...</p><p>Second text></p>' } I am looking to ...

Is there a way to access an SD card by clicking on an HTML link using JavaScript?

UPDATE: I am seeking a way to embed an HTML file with JavaScript or jQuery that can directly access the contents of the SD card while being opened in a browser. Currently, I have posted code for accessing it through an activity, but I want to be able to d ...

Building a contact form in Angular and sending emails with Nodemailer

Currently, I am in the process of setting up a contact form for my website. Since I am utilizing a MEAN stack, it made sense to incorporate the nodemailer module for sending emails. In order to handle this functionality, I have established an endpoint &ap ...

Setting up redux with Next.js: a step-by-step guide

After setting up redux in this manner, everything is functioning properly. The _app.js file has been reorganized as follows : import App from 'next/app'; import { Provider } from 'react-redux'; import withRedux from 'next-redux-wr ...