Capybara with Angular Material Select

Is it possible to use select in RoR RSpec + Capybara? I typically use:

select 'something', from: 'select_name'

However, this method does not work for Angular's md-select. Capybara displays the following error message:

Capybara::ElementNotFound: Unable to locate the select box with id "select_id"

Answer №1

After encountering an issue with Riddler's solution not being able to find the correct option, I decided to revamp it using CSS selectors. The revised code now works smoothly:

def select_gender(name, from:)
  find("md-select[name='#{from}']").click
  find('md-select-menu md-content md-option div', text: name).click
end

To use this function, simply provide the display value of the desired option (not the value attribute):

select_gender "Female", from: 'gender'

Answer №2

I came up with a clever solution by creating a custom md_select method for Capybara.

def md_select name, from: ''
  puts 'Make sure to include the `from:` parameter when using md_select. For example: `md_select select_value, from: select_name`' if from.blank?

  find(:xpath, "//md-select[@name='#{from}']").click
  find(:xpath, "//md-select-menu/md-content/md-option/div[text()='#{name}']").click
end

Now, in RSpec, we can simply call our custom method:

md_select select_value, from: 'select_name'

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

Utilizing an AngularJS service to communicate with a web API

Having trouble retrieving data from a web api and passing it back to a JavaScript file. I've tried using http://localhost:8584/api/Testing/5 to see if there are any results, but no luck so far. //This is the JavaScript controller that calls the serv ...

Methods for initializing state before each test in AngularJS

Within my test setup, a service is injected using beforeEach: beforeEach(inject(function($rootScope, $state, $injector, $controller, MyService) { var state = $state; scope = $rootScope.$new(); myService = MyService; ctrl = $controller(&apo ...

Ways to effectively utilize the $getDownloadURL() promise within the ng-repeat directive in Angularjs 1.6

I am currently in the process of developing a Single Page Application (SPA) using AngularJS 1.6 along with Firebase for database and storage functionalities. One of my goals is to display an image from Firebase storage on my HTML page. I have implement ...

CORS has prevented the redirection

As I am sending a redirect from a POST API to an adfs server via HttpServletResponse containing a URL with status 302, I encountered the following error: The XMLHttpRequest cannot load Resource A. The redirect from Resource A to Resource B has been bl ...

Providing inputs to $resource

Imagine that we have the following code: angular.factory('Service', [ '$resource', function ($resource) { return $resource('/path/:id', {id: '@id'}); }]) If we use the following code in our controller: v ...

Navigating through C# Web API routing in tandem with Angular's routing capabilities

Can a MVC application be configured to use routing from WEB API exclusively, with Angular handling the rest using its routeprovider? Upon running my application, I encounter the following error: GET http://localhost:8080/Views/Home/Index.html 404 (Not Fou ...

Tips for accessing and manipulating the parent, sibling, next, and previous elements of the current element with AngularJS

Below is an example of HTML code where I have linked $scope properties and values to controls: This is the function that triggers when an image is clicked and changes the path of the images: $scope.ratingClick = function(e) { $log.info(e.currentTarge ...

Issues with Angular UI Router where the views are not being rendered

Trying Angular UI router for the first time, but facing issues with views not being called properly. Take a look at the Plunker example: http://plnkr.co/edit/cBfR6u2BPJvKN16vi6hG?p=preview Is there anything noticeable in the router configuration? device ...

I encountered difficulty in testing the Angular Material Select Component due to complications with the CDK Test Harness

While working on testing a component that utilizes Angular Material Components, I came across the CDK Test Harness and decided to use it to retrieve the count of options in the Mat Select component. You can find more information about the CDK Test Harness ...

Utilizing AngularJS to retrieve associated information from users via a JSON API

I'm currently utilizing the Ionic framework and my inquiry relates to AngularJS. I've set up a JSON API using Ruby on Rails and for authentication, I've opted for ng-token-auth + devise-token-auth. User JSON: { "data": { "id": "1", ...

Learn the methods for successfully transferring dynamic values from Angular to a jQuery script

This is the script that I have included in my HTML code: <div class="progress-bar"></div> <script type="text/javascript"> $('.progress-bar').gradientProgressBar({ value: $(this).attr('$scope.moodvalue'), ...

Tips for increasing the height of a Kendo-UI grid to 100% within an AngularJS 1.x environment

Encountering an issue, I needed a Kendo UI Grid widget with its height set to 100% of the surrounding <div>. Attempting basic CSS styling on the grid proved unsuccessful: html, body { height:100%; } .expand-vertical { height: 100%; min-h ...

Making a request to the specified URL using the $http.get() method with an email parameter that is currently empty

I'm having trouble sending an HTTP GET request with the email parameter in the params section of the code below: $http.get('api/me', { params: { email: email } }); However, on the backend, I am receiving empty parameters, m ...

Converting JSON data into an image within a Prawn PDF document

Currently, I am facing an issue within my Rails 3.2 app where I am using the Prawn PDF in combination with the signature-pad gem. The problem arises when attempting to convert JSON data into an image for rendering in the PDF. Upon completion of the signat ...

Parent state in AngularJS, identifying state transitions

Currently, I am utilizing ui-router in my project. Within the application, there is a state labeled user, which showcases a list of users. Additionally, there exists another state known as user.edit, presenting a form along with a submit button for user in ...

Updating an array within a service across different controllers in AngularJS

My goal is to create an array within a service that can be updated from different controllers. The purpose of this setup is to ensure that the array is accessible across all controllers. I need the ability to add new items to the array as well as delete ex ...

Step-by-step guide on making a post request to the Facebook Graph Api with Httparty in a Rails application

I'm currently working on developing a bot for Facebook Messenger, and I need to make a post request call to the Facebook Graph API. The sample code provided by Facebook is in Node.js, but I am working with Rails as my backend framework. Sample Code ...

AngularJS Material Design Tabs with See-Through Style

Is there a way to make the md-tabs of angularJs Material have transparent background for the tab names (headers)? I've tried different methods but none have worked so far. I'm under the impression that this should be the default behavior, but fo ...

Discovering browser back button press event utilizing Angular

Can we identify when a user has navigated to a page using the browser's history back button? I am looking for a solution in angular.js without relying on angular routing. Additionally, it should also detect if a user returns to a form after submitting ...

Pre-selected default value in select box using ng-options

I'm working on setting a default value in my select box, retrieved from the database, using ng-options. Here's my view: <select class="form-control samlength modalinput" ng-options="p.procid as p.procname for p in proce ...