Unlocking the power of site JavaScript functions with webdriverIO

Struggling with accessing code from the browser console? Specifically, encountering issues with a Tawk_Api function Tawk_API.hideWidget();. Attempts to utilize browser execute and call have resulted in an error message stating that Tawk.Api is not defined.

Here's an example of the code:

 var expect = require('chai').expect;  
    function HideTawk (){
        Tawk_API.hideWidget();
    }
    describe('', function() {
        it('should be able to filter for commands', function () {
            browser.url('https://arutech.ee/en/windows-price-request');
            $('#uheosaline').click();
            browser.execute(HideTawk());
        var results = $$('.commands.property a').filter(function (link) {
            return link.isVisible();
        });
        expect(results.length).to.be.equal(3);
        results[1].click();
        expect($('#getText').getText()).to.be.equal('GETTEXT');
    });
});

Updated working function:

  function HideTawk (){
        return new Promise(function(resolve, reject) {
            Tawk_API.hideWidget();
        })
    }

Furthermore, using browser.execute(HideTawk()) is incorrect; it should be replaced with browser.call(HideTawk());.

For more information, check out the documentation:

Answer №1

Check out this code snippet from my application's base object that demonstrates how to make API calls:

_callClientAPI(func, args) {
    let attempt = 1;
    return new Promise(async(resolve, reject) => {
      while (true) {
        if (attempt > this._pollTrials) {
          reject(`Failed to fetch the element within ${this._pollTimeout} seconds.`);
          break;
        }

        let result;
        try {
          result = await func.call(this.client, args, false);
        } catch (error) { }

        if (result && result !== '') {
          resolve(result);
          break;
        }

        await this.wait();
        attempt++;
      }
    });
  }

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

My goal is to retrieve all the links from a website and systematically click on each one

My goal is to fetch all the links from a website and then click on each one individually. However, when I run the code below, I am able to retrieve the total count of links correctly but I encounter a `null pointer exception` when trying to navigate to the ...

Issue encountered while compiling ReactJs: Unexpected token error found in App.js

I executed the commands below. npx create-react-app github-first-app npm install --save react-tabs npm i styled-components npm install git-state --save using the following code files App.js import React from "react"; import Layout from " ...

Conflicts in SwiperJS Timeline Management

Having a Timeline on my Website using SwiperJS presents challenges with conflicting functions. The goal is to navigate swiper-slides by clicking on timespans in the timeline. The desired functionality for the timeline includes: Sliding to the correspondi ...

Transform an array containing objects into a single object

Currently exploring the Mapael Jquery plugin, which requires an object to draw map elements. In my PHP code, I am returning a JSON-encoded array of objects: [ { "Aveiro": { "latitude": 40.6443, "longitude": -8.6455, ...

"Utilizing Express.js and PHP for Streamlined Functionality

I have been working on a project that involves using expressjs, Php, Html, and MongoDB. Here is the code snippet from my "Index.Html" File: <form action="/Login" method="POST"> <input type="text" placeholder="name" name="Username"> <in ...

When using CSS media queries and Javascript, the menu behaves differently on desktop compared to mobile devices. While it works well on

Encountering a difficulty with CSS media queries and a UL tag involving two menus (left and right) along with a search bar. The issue arises when the right menu goes off screen on desktop, even though it works correctly on mobile. When users activate the m ...

What is the maximum allowable size for scripts with the type text/json?

I have been attempting to load a JSON string within a script tag with the type text/json, which will be extracted in JavaScript using the script tag Id and converted into a JavaScript Object. In certain scenarios, when dealing with very large data sizes, ...

The transmission of specific properties to a customized component is not successful

I recently developed a custom component that is designed to receive a color name from the parent component and update that color in the state of the parent component. Despite completing all the necessary code, the new color is not being saved, resulting in ...

Is there a way to activate a click event when I click on a button that is located outside of the dialog element?

In my Vue 3 app, I am using the native HTML dialog element as a modal. I have managed to position a button outside of the modal with absolute positioning. However, I am facing an issue where I cannot trigger a click event (displayNextModal) when clicking ...

Having trouble transmitting data from the View to the Controller

Need help with this issue. I'm having trouble passing my data to the controller. Below is my ajax code. <script type="text/javascript"> $(document).on("click", "#login_button", function () { var userName = document.getElementById(" ...

What causes the React white screen of death to disappear when this code is commented out?

Currently, I am working on a React application that pulls trivia questions and answers from an API to create a game interface. Everything has been going smoothly with the development process until I imported a decode function to properly display the trivi ...

You do not have the authorization to access this content

I have been working on a Laravel web application to upload images into a data table and allow users to download the uploaded image on click. Initially, everything was working fine until I made changes in the code from return '{!! Html::link('ima ...

A warning has been issued: CommonsChunkPlugin will now only accept one argument

I am currently working on building my Angular application using webpack. To help me with this process, I found a useful link here. In order to configure webpack, I created a webpack.config.js file at the package.json level and added the line "bundle": "web ...

Properly implementing prototypal inheritance: best practices

While there are numerous discussions on prototypal inheritance in JavaScript already, I assure you this is not just another lazy copy. Having thoroughly read all existing threads, I've noticed a plethora of syntactic approaches and varying answers whi ...

Looking for a distinctive button featuring a plus sign - eager to give it a click!

The code snippet is: <button class="btn btn-default btn-xs" style="padding:0 5px" id="addPiidRelatedNumberBtn_332741000" ng-click="AddPiidRelatedNumber($event)" ng-show="EnableEditable && CanEdit"> <span class="glyphicon glyphicon-plus" t ...

What is the process for utilizing a .js file as a node command on a global scale?

I have a .TS file that contains all of my utility functions for various projects. Every time I need to use these functions, I find myself copying and pasting the file into the project folder. I am familiar with node scripts and FS for file system manipulat ...

How can I make Requirejs and Threejs OrbitControls work together?

Having trouble implementing OrbitControls with requirejs. Here's my configuration: I attempted to follow guidance from this post on Stack Overflow RequireJS and THREE.js Orbit Controls, but it's not working. requirejs.config({ baseUrl: &ap ...

Error message due to an undefined function in Angular datatables Fixed Columns

I recently implemented angular datatables with fixed column in my application. Here is the HTML code I used for the view: <div class="row" ng-controller="PerformanceCtrl"> <table id="example" datatable="" class="stripe row-border or ...

How can you enable fullscreen for a featherlight iFrame?

I have implemented Featherlight to display an iframe within a popup modal on my website. If you click the iframe button, you can see a demo of how it works. One issue I am facing is that the generated iframe tag by Featherlight does not include allowfulls ...

Having trouble retrieving a value from the $http promise, causing the code within the then() function to not run as expected

In the past, I encountered a challenge with the $http service which I managed to solve by creating a dedicated service for handling my requests. However, as my requests grew larger, this solution started to seem inefficient. Instead of just assigning a sim ...