Steps for clicking on the center of a leaflet map with protractor

I'm currently facing an issue where I am attempting to click on the center of a map located in the second column of the webpage, which has an offset. However, I am encountering a problem where the cursor always points to the center of the page instead:

https://i.sstatic.net/jUPb8.png

To achieve this, I have tried to calculate the location by adding half of the width and height. Below is the code snippet I have been using:

    it('should select center point', async () => {
        const map = pageObject.getMap(); // $('.map-container')
        const size = await map.getSize();
        const location = await map.getLocation();
        const halfWidth = parseInt(await map.getAttribute('clientWidth'), 10) / 2;
        const halfHeight = parseInt(await map.getAttribute('clientHeight'), 10) / 2;
        const x = location.x + halfWidth;
        const y = location.y + halfHeight;
        await browser
          .actions()
          .mouseMove(map, { x, y })
          .click()
          .perform();
        console.log('size', size); { height: 482, width: 840 }
        console.log('location', location); { x: 523, y:145 }
        console.log('halfWidth', halfWidth); // 420
        console.log('halfHeight', halfHeight); // 241
        console.log('x', x); // 943
        console.log('y', y); // 386
        debugger;
      });

The window size is 1380*668, so the coordinates 943 and 386 should be correct. It's puzzling why it's not functioning as intended.

I also attempted to disregard the offset, but still encountered issues:

    await browser
              .actions()
              .mouseMove(map, { x: halfWidth, y: halfHeight })
              .click()
              .perform();

Additionally, I experimented with using map.getWebElement() and changing the selector, but unfortunately none of these fixes worked for me.

Answer №1

After some experimentation, I have managed to come up with a workaround. By default, when clicking on the map element, protractor automatically clicks on the center:

await pageObject.getMap().click();

If you want to click on a specific address instead, simply enter the address in the geocoder bar and then click on the map to set the center. Unfortunately, I couldn't figure out how to achieve this using moveMove(element, { x, y }).

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

Having trouble importing the hash-set module in TypeScript/SystemJS?

In the midst of developing an Aurelia project with TypeScript to generate JavaScript, I decided to incorporate another custom library called 'hash-set' (installed using jspm install npm:hash-set --save). However, I encountered difficulties in act ...

Trouble Integrating svgr/webpack with Webpack 5 and SingleSpa

I've been grappling with this issue for the past week. Despite scouring through numerous Stack Overflow threads and reading the SVGR/WEBPACK documentation, I haven't been able to find a solution. I decided to upgrade an old React single-spa appl ...

Combining Multiple TypeScript Declaration Files into an NPM Package for Seamless Importing with index.d.ts

I have a unique package structure that includes: myPackage/ |- types/ | |- type1.d.ts | |- type2.d.ts |- src/ | |- someUtilities.ts |- index.ts |- package.json |- tsconfig.json In my package, the index.ts file is handling imports and exports for all th ...

Angular: Animate newly updated items in a constantly evolving and refreshed list

I'm facing a challenge with my template that includes a simple list with animated items (:enter & :leave animations). @itemAnimation *ngFor="let item of list; There's also an "ADD" button that triggers a modal dialog for users to add new it ...

Having trouble with the Angular 2 router event not triggering on the initial try?

When navigating from one component to another, I want to access the URL of the previous route once the new route has been reached. In the constructor of the component being navigated to, I have included the code below. However, I am facing an issue where t ...

I am attempting to execute a Selenium program in Eclipse but I seem to be encountering an issue... It is displaying an error message

An issue occurred within the main thread: java.lang.IllegalStateException. It seems that the driver executable path needs to be set using the webdriver.gecko.driver system property. For more details, please refer to https://github.co ...

Tips on adding an array value to the XPath syntax while conducting a search in Selenium IDE

As a novice in Selenium, I might not be articulating my query clearly. I am working with Selenium IDE version 3.17.0 and attempting to validate the presence of device names on a web page under test. These device names are stored in an array: execute scrip ...

Step by step guide on transferring data from one Angular 7 component to another component following API response retrieval

I have been tackling an issue related to an API recently. Upon receiving a response from the API, my goal is to pass the value to a child component. In this component, I will run a method to obtain a response and display it on the screen. Example Code: ...

Launching WebDriver more efficiently with Selenium in Python

Does anyone know of a method to speed up the initialization time of the chromedriver in Selenium? Currently, it's taking approximately 6 seconds to start, which is causing a significant delay in my code execution. ...

Is it possible to circumvent a submit button using Python Selenium, even if the button becomes disabled after using .clear() or .send_keys()?

Is there a way to trigger the clicking of a button using Selenium, even when the button becomes disabled after using the clear or send_keys methods? Before: https://i.sstatic.net/NGriJ.png This is the initial page status when accessing its URL. However, ...

Can an interface be designed to have the option of containing either one property or another?

I am in need of an interface that resembles the following structure: interface EitherOr { first: string; second: number; } However, I want to make sure that this interface can only have either the property first or second. Do you think achieving this ...

Using TypeScript import statements instead of the <reference path...> in an ASP.NET Core web application: A step-by-step guide

Understanding the Setup I initially had a functional TypeScript Hello World in my ASP.NET Core Web application. To compile TypeScript, I used the NuGet package "Microsoft.TypeScript.MSBuild" Version="4.4.2" along with a tsconfig.json f ...

What is the reason behind installing both Typescript and Javascript in Next.js?

After executing the command npx create-next-app --typescript --example with-tailwindcss my_project, my project ends up having this appearance: https://i.stack.imgur.com/yXEFK.png Is there a way to set up Next.js with Typescript and Tailwind CSS without i ...

How can I gather information from members who have already signed up?

I have a form that submits data to the Angular Firebase database. Once the form is submitted, I want to display the previously submitted data in the form if the user signs in again. Below is my .ts file: import { Component, OnInit } from '@angular/c ...

Working with Angular: Managing an Array of Objects

After retrieving an array of objects using the code snippet below: this.serviceOne.getRemoteData().subscribe( data => this.MyArray.push(data) ); I encounter issues when trying to iterate through the array using the code snippet bel ...

What is the process of organizing information with http in Angular 2?

Currently, I am working through a heroes tutorial and have made progress with the code so far. You can view the code <a href="https://plnkr.co/edit/YHzyzm6ZXt4ESr76mNuB?preview" rel="nofollow noreferrer">here</a>. My next goal is to implement ...

What is the process for developing a dropdown search feature with automatic selection in Angular?

Currently, I am in the process of developing an input field that offers autocomplete functionality for the text being entered. Additionally, I would like to display suggestions below the input field in select options and have the relevant option highlighte ...

Retrieve the numerical value of the buttons

This HTML code is customized for my selenium project. <button class= "message-anywhere-button mn-connection-card__message-btn button-secondary-medium" aria-label="hello" data-ember-action="" data-ember-action-62="62"> <span aria-hidden="true"> ...

How to implement a custom pipe for dynamically changing image URLs in Ionic 3's image tag

I am trying to set authentication headers for images called from an image tag (<img>). To achieve this, I have created a custom pipe named secureimages using the command ionic g pipe secureimages. This pipe intercepts the HTTP requests in an interce ...

What is the best way to duplicate a Typescript class object while making changes to specific properties?

I have a Typescript cat class: class Kitty { constructor( public name: string, public age: number, public color: string ) {} } const mittens = new Kitty('Mittens', 5, 'gray') Now I want to create a clone of the inst ...