Commit to choosing an option from a dropdown menu using TypeScript

I just started learning about typescript and I have been trying to create a promise that will select options from a drop down based on text input. However, my current approach doesn't seem to be working as expected:

case 'SelectFromList':
     return new Promise( (resolve, reject) => {
         this.retrieveElement(driverscr.getPageElementFromJson(screenName, fieldName)) // retrieveElement gets the page element.
             .click()
             .then(() => {
                 resolve();
             })
             .thenCatch( () => {
                 reject();
             });
       });

Answer №1

As previously mentioned, I have not attempted to choose an item from a dropdown in the manner you are currently doing. Here is a method that has been successful for me in the past. In this example, there is a dropdown menu containing a list of domains to which I wish to add a user. I locate the option that corresponds to the desired domain and click on it. I hope this approach assists you in reaching a resolution.

public static domainSelectorList = element.all(by.repeater("d in vm.customer.domains")

public static addUserToDomain(domain: string): Promise<void> {
    return this.domainSelectorList.filter((elem: ElementFinder) =>
        elem.getWebElement()
            .getInnerHtml()
            .then((innerHtml: string) =>
                innerHtml.indexOf(`@${domain}`) > -1)).first().click();
}

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

Transmitting image data (blob) from the frontend to the backend using Next.js and tRPC (T3 stack)

I'm currently facing a challenge in sending a leaflet map image from the backend to the frontend using the leaflet-simple-map-screenshoter library for capturing the image. The library returns a blob, which I need to transmit back to the backend and sa ...

Error TS2307: Module 'angular' could not be located

I have encountered an error in my project and despite searching for solutions, I haven't been able to find one that addresses my specific issue. It seems like a simple problem, but I can't figure out what I'm missing. The error arises in th ...

Distribute Test Specifications Across Nodes Using Protractor and Selenium Grid

After setting up a Selenium Grid with one server for the hub and 10 other servers hosting one node each, my Protractor automated tests are running smoothly. However, I am looking to distribute my approximately 400 tests across all defined nodes in multiCap ...

Limiting the parameter type in Node.js and TypeScript functions

Currently working on a Node.js project utilizing TypeScript. I'm attempting to limit the argument type of a function to a specific base class. As a newcomer to both Node and TypeScript with a background in C#, I may not fully grasp some of the langua ...

Angular HttpClient Catch Return Value

In my quest to develop a universal service for retrieving settings from the server, I've encountered an issue. When errors arise, I want to intercept them and provide a default value (I have a predetermined configuration that should be utilized when e ...

Encountering issues with importing a module from a .ts file

Although I have experience building reactJS projects in the past, this time I decided to use Node for a specific task that required running a command from the command line. However, I am currently facing difficulties with importing functions from other fil ...

Extracting a single column value from a web table through printing

I am struggling to retrieve and display all the column values from a table based on a specified parameter. When the parameter matches, I want to print out all the corresponding column values. Unfortunately, this functionality is not working as expected in ...

How about: "Loop through an array of objects fetched from an observable and initiate an HTTP request for each object's ID?"

Using Angular routing, in the component's ngOnInit method, I retrieve a genre ID through an observable. Within this observable, a service method is called that makes an HTTP request. this.movies: Movie[]; ngOnInit() { this.route.paramMap.sub ...

Rendering ng-include before setting the source

Is there a way to prevent the ng-include directive from trying to render before a value on scope is set? Consider the following example: <ng-include src="'./lib/templates/' + $parent.currentEditable.editTemplate"></ng-include> It s ...

An incorrect format is being utilized for updating "ChromeOptions.AddUserProfilePreference" in Selenium using C#

Updating Chrome Profile preferences in Selenium C# to make a popup disappear can be achieved by including the following line as part of Chrome Options. string url = "https://google.com"; string envName = "xyz.qa"; ChromeOptions.AddUser ...

Tips for utilizing the 'crypto' module within Angular2?

After running the command for module installation: npm install --save crypto I attempted to import it into my component like this: import { createHmac } from "crypto"; However, I encountered the following error: ERROR in -------------- (4,28): Canno ...

"Patience is key when it comes to waiting for an HTTP response

Looking for a solution in AngularJS, I have a service that calls the backend to get some data. Here is how the service looks: app.factory('myService', ['$http', '$window', '$rootScope', function ($http, $window, $ro ...

The type 'number | { percent: number; }' cannot be assigned to the type 'string | number | undefined' according to ts(2322) error message

Presently, I am engaged in a project utilizing React and Typescript, where I am working on implementing a progress bar using react semantic-ui. I have encountered a typescript error in my code. Here is the segment causing the issue: import React, { Compo ...

Tips for verifying modifications on a webpage after refreshing it using Selenium and Python

I am facing a challenge where I need to continuously refresh a web page as quickly as possible and monitor for any changes. However, my initial approach did not yield the desired results. My attempt looked something like this: while True: driver.get( ...

Tips for keeping a login session active on multiple tabs

As I am in the process of developing a website, one issue I am facing is determining the most effective method to maintain user login sessions. Currently, I am utilizing Html5 web storage known as "session storage" to keep track of whether a user is logged ...

AngularJS: The $http.get request for JSON data from eBay is malfunctioning

I'm feeling lost and needing some guidance. When I make an ebay search request, the browser displays a JSON response. I saved this JSON in a file named v1 on my website. However, when I tried to access it through a $http.get request, it returned null. ...

Pass the $scope object from a controller to a modal controller

I am facing an issue with transferring the $scope variable from ctrlone to ctrltwo, which is a modal window on my page. When I open the modal in ctrlone, my code looks like this: var modalInstance = $modal.open({ templateUrl: 'Modal.html&ap ...

Angular two-way selection of dependent dropdowns

I am working on creating a dependent select/dropdown feature. Here is a sample JSON data that I have: [ { "id": 15695, "username": "user1", "address": { "id": 16794, "location": "O Treviño de San Pedro" }, "jobs": [ ...

Tips for sorting through and minimizing data based on the most recent date

info = { start: 1, data: [ { name: 'Maria', date: '2020-02-15 }, { name: 'Paula', date: '2020-06-10 }, { name: 'Eva', date: '2020-12-05 }, { name: 'Sophia', date ...

What is the way to send custom properties to TypeScript in combination with StyledComponents?

Encountering an error while attempting to implement Styled Components 3 with TypeScript: TS2365: Operator '<' cannot be applied to types 'ThemedStyledFunction<{}, any, DetailedHTMLProps<TableHTMLAttributes<HTMLTableElement>, ...