Finding the right dropdown option by matching text

Is it possible to choose a dropdown option based on its text?

Here is the HTML code snippet that demonstrates this:

<li title="Add Page" class="dropdown-header ng-scope" data-ng-if="selectedPage">Add Page</li> 
<li title="Add page before the current page" data-ng-if="selectedPage" class="ng-scope">
<a data-ng-click="addPage(selectedPage, 'before')">Before Selected</a>   </li>
<li title="Add page after the current page" data-ng-if="selectedPage" class="ng-scope">
<a data-ng-click="addPage(selectedPage, 'after')">After Selected</a></li>

Answer №1

To select the "Before Selected" option, you can utilize either by.xpath() to locate and click on the a element:

element(by.xpath('//li/a[. = "Before Selected"]')).click();

Alternatively, you can also achieve this by using link text:

element(by.linkText("Before Selected")).click();

Answer №2

When it comes to choosing options from my dropdowns, I stick with:

.click().sendKeys(); 

and so far, I haven't encountered any issues.

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

Utilize JQuery to Extract HTML Elements

I'm working on developing a Chrome extension and one of my tasks is to extract specific text from the webpage I am currently visiting and store it in a variable. I have been attempting to achieve this using jQuery, however, none of the solutions I&apo ...

Express.js automatically sets timeouts for requests to static files

I've been facing this issue for several weeks now - after launching, Express functions properly for a few hours and then suddenly stops serving static files. The situation is as follows: GET / 304 153ms GET /js/bootstrap.min.js 200 120000ms GET /img/ ...

Can lazy loading be implemented for the video tag using JavaScript?

Currently, I am in the process of working on a project that entails incorporating three videos onto the homepage. However, loading them simultaneously is causing a significant decrease in load time. In addition, I prefer to utilize the <video/> tag ...

Locating the ASP.NET validator's Control with the help of JQUERY or basic Javascript

On my webpage, I have several textboxes with corresponding ASP.NET validators for validation. I know that I can validate all the validators using a JavaScript function: Page_ClientValidate("myvalidators") where "myvalidators" is the group name of my val ...

Tips for transferring data from a service to a method within a component

I have a service that successfully shares data between 2 components. However, I now need to trigger a method in component A when an event occurs on the service (and pass a value to that component). Can someone guide me on how to achieve this? I have seen ...

a guide to presenting information in a horizontal layout within a single table using the Laravel framework and Vue.js

I have 2 tables: table 1 ________________ | name_id name | | 1 john | | 2 heaven | |_______________| table 2 _______________________ | id name_id product | | 1 1 bag | | 2 1 shoes | |______ ...

AngularJS $resource sends the id as a query parameter rather than including it in the URL

I'm trying to retrieve data from a rest API by using the product id as part of the URL, rather than as a query parameter. Here is the factory code: .factory('Products', ['$resource', function($resource) { return $reso ...

What is the best way to redirect nodejs requests to a separate nodejs application?

Hello! I am currently working on a project to create an API gateway using Node.js and Express. The goal is to showcase a small-scale microservices architecture by routing requests to different microservices. For instance, if I have microservices A, B, and ...

Issue with React Google Maps Api: Error occurs while trying to access undefined properties for reading 'emit'

I'm trying to integrate a map using the google-map-react API, but I keep encountering the following error: google_map.js:428 Uncaught TypeError: Cannot read properties of undefined (reading 'emit') at o.r.componentDidUpdate (google_map.js: ...

Implementing concurrent Scrapy operations with multiple Selenium instances

Currently, I am in the process of scraping multiple URLs using a combination of Selenium and Scrapy. In order to streamline this operation, my goal is to establish a group of shared Selenium instances that can be accessed by any Request when necessary, and ...

What is the process for customizing the color of a w3.css button?

<link type="text/css" href=" https://www.w3schools.com/w3css/4/w3.css" rel="stylesheet"> <div class="w3-bar w3-red"> <a class="w3-bar-item w3-button w3-hover-blue">Button</a> </div> I am looking to implement a funct ...

Running a repeated script

I recently discovered a fantastic script called Typer that creates a typewriter effect. However, I noticed that it does not have a built-in method to loop the animation once it reaches the end. Does anyone have any suggestions on how to achieve this? t ...

Angular: Identifier for Dropdown with Multiple Selection

I have recently set up a multi select dropdown with checkboxes by following the instructions provided in this post: https://github.com/NileshPatel17/ng-multiselect-dropdown This is how I implemented it: <div (mouseleave)="showDropDown = false" [class. ...

Guide to integrating Selenium Firefox browser within a PyQt4 frame

Is it possible to integrate Selenium with PyQt4 to embed a controllable browser into a Qt4 frame or widget? I have proficiency in both Selenium and PyQt4, and I believe combining them would greatly enhance the program I am currently developing. Can this in ...

The iFrame is set to a standard width of 300 pixels, with no specific styling to dictate the size

My current challenge involves utilizing the iframe-resizer package to adjust the size of an iframe dynamically based on its content. However, even before attempting any dynamic resizing, I encounter a fundamental issue with the basic iframe: it stubbornly ...

Issues with HTML structure across various devices

Being a novice in web development, I've been experimenting with creating a modal body. https://i.sstatic.net/Qk5BR.png The code snippet below represents my attempt at structuring the modal body: <div className="row modalRowMargin textStyle" > ...

Double Ajax calls being made in Laravel application

I am working on a Laravel application for managing tasks. The application has a form with four fields: one for the CSRF token, two hidden fields for IDs, and an input field to capture the task title. For submitting the form, I have implemented AJAX. Howev ...

Having trouble verifying credentials to access the npm.fontawesome.com registry for installing pro packages

After following the instructions in font awesome documentation, I have globally configured my host. My current setup is: npm config set "@fortawesome:registry" https://npm.fontawesome.com/ npm config set "//npm.fontawesome.com/:_authToken" "${NPM_FONT_AW ...

Leveraging the power of Express.js, transmit local data alongside a

Why can't I display the active user in my view using plain HTML when console log shows it? Here is the code snippet: app.post('/', function (req, res) { var user = { user : req.body.username }; res.render('doctor_hagfish/pets&ap ...

Error: Codeception unable to locate and load Webdriver module

Encountering an issue while attempting to run Codeception with Selenium on Windows 8 in my new role. Error Message: [Codeception\Exception\Configuration] Webdriver could not be found and loaded. To address this problem, I manually initiated th ...