In the test environment, only a portion of the JavaScript code is executed, but it functions properly in both the production and development environments of

Rails 3

Currently facing an issue with a list inside a form:

<%= form_for @article do |f| %>
  <ul>
    <% @product.each do |p| %>
      <li id="product_<%=p.id%>">
        <div>
         <%= f.radio_button(:p_id, p.id, class: 'hidden') %>
        </div>
      </li>
    <% end %>
  </ul>
  <%= f.submit 'submit', :id=>"submit_category", :class=>'hide' %>
<% end %>

Implemented a javascript function to handle the selection of radio buttons upon clicking the li element within the form.

<script type="text/javascript">
  $('li').click(function() {
    $(this).find('input[type=radio]').attr('checked', true);
    $('#submit_category').click();
  });
</script>

Encountering an issue specifically in the test environment where the radio button is not selected despite the form being submitted, resulting in a validation error.

Conducting tests using Cucumber + Selenium + Capybara. Excerpt from the testing script:

When /^I click on the "(.*?)" product$/ do |product_name|
  @product = Product.find_by_name(product_name)
  page.find('li', id: "product_#{@p.id}").click
end

Answer №1

Could it be beneficial to enclose the code within a $(function () { ..your code }) (domready) callback? That might solve the issue.

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

The locator for the span class cannot be found or interacted with in Selenium

Here is the HTML code snippet for a span element: <td class="header-logout-btn"> <a href="logout.htm" class="btn switch-btn"> <i class="fa fa-times"></i><span class="hidden-xs">Home</span> </a> </td> I ...

HTML table containing radio buttons styled with Font Awesome icons

I'm having some trouble getting a radio button with Font Awesome to work properly within an HTML table. Outside of the table, it functions as expected, but inside the table, it only seems to hide/show between the two states without displaying the chec ...

What sets Vuex apart from a traditional store object?

I'm currently utilizing Vuex for Vue 2 which is similar to Redux for React. Recently, I came across a helpful example that demonstrates updating a counter. Here is the code snippet: import Vuex from 'vuex' import Vue from 'vue' V ...

Anyone faced the issue of jquery_ujs corrupting the callback URL in Rails 4, causing problems with updating screens via Ajax?

Encountering a Catch-22 situation with jQuery in my Rails app - when I include jquery_ujs, it pulls the wrong URL from Rails during execution, leading to quiet errors when attempting to access non-existent URLs on the server. However, if I omit jquery_ujs ...

Unable to make a post using vue.js

I am facing an issue while trying to submit form data using "vue-resource" in my code. The error message I receive mentions a problem with the use of this method alongside vue-cli and vuetify. Error [Vue warn]: Error in v-on handler: "TypeError: this.$h ...

I'm looking to streamline my code by creating shared functionality across multiple reducers with the help of create

Previously, in the older way of using Redux, we could create a reducer like this - handling different action types but with the same action: export default function authReducer(state = initialState, action) { switch (action.type) { case AUTH_ERROR: ...

Is there a way to incorporate expandable content on a Drupal node page using Javascript?

Is there a Drupal Module available that can display a trimmed version of content on the node page and expand it when clicking on a "Read More" link? Thank you! ...

What is the best way to invoke an HTML file using a jQuery function in a JavaScript file?

When I call an HTML file from a jQuery function using require(), I am encountering an issue where I am unable to link the CSS with the HTML file. After running the file, only plain HTML is displayed without any styling. The structure of my HTML file is as ...

Unable to execute PHP alongside a JavaScript event listener

Using PHP, I am creating a canvas for writing and the text output will appear in a textarea (handled by other functions). There are additional input tags like a title to gather user input. The values from these input tags (title and textarea) will be submi ...

Is it possible to retrieve information from a json file?

I am looking to extract specific elements from a JSON response fetched using the YouTube API. Here is an example of the response I receive in my script: { "version": "1.0", "encoding": "UTF-8", "feed": { // Details of the feed... } } My goal ...

Output the initial value and subsequently disregard any values emitted during a specified time interval

Check out my code snippet: app.component.ts notifier$ = new BehaviorSubject<any>({}); notify() { this.notifier$.next({}); } app.component.html <div (scroll)="notify()"></div> <child-component [inp]="notifier$ | async" /> ...

What is the best way to choose a random number using jQuery?

<div class="yyy"></div> <p>...</p> <pre><code>let content = $(".xxx").text(); $(".yyy").html(content); http://jsfiddle.net/tQeCv/ I just require this specific input : Number is {1|2|3|4}, and {one|two|three|four} ...

Exploring Methods to Access External Iframes Using PHP or JavaScript

I need assistance tracking my package that was sent through the local post service. The tracking information can be found at this link: . Using the tracking number RF166699170SK, I should be able to locate the package. However, when I attempt to retrieve ...

Seeking the parent class name in Selenium using ChromeDriver

Does anyone know how to find the parent class name of an element? I'm struggling to locate it. Check out the image below, which shows the element I'm trying to find the parent class name for. https://i.stack.imgur.com/hY1f8.png Any suggestions ...

How can I utilize the parseFloat feature within my dedicated parseFloat function located in an angular factory?

What is the solution for accessing parseFloat within an angular factory function named parseFloat? angular .module('myApp') .factory('mathService', [MathService]); function MathService() { return { parseFloat: myGl ...

The trim() method in Vue.JS does not properly handle trimming a passed string

I've been attempting to eliminate white space from a property of one of the returned objects using the .trim() function, but it's not working as expected. Even after trying JavaScript functions like .replace(/\s/g,''), the issue p ...

Send the ID of the checkbox to a PHP file using AJAX

Is it possible to generate a network graph by selecting checkboxes? When I choose one or more checkboxes and click the button, I expect to see a network graph with the selected checkboxes. It almost works, but when I select multiple checkboxes, only one ...

"Efficiently handle JSON and binary data passing with the enhanced functionality of Express Body Parser

Within my express app router, I have routes set up to handle both POST requests with JSON data and binary data. The issue arises when I use body parser to parse the JSON data, as it incorrectly interprets the binary data as JSON and causes errors during th ...

Using Angular 2 to fetch barcode scanner information without the need for HTML input or textarea elements

Currently, I am in the process of developing a web application that utilizes a barcode scanner, specifically the Motorola TC55 model. My primary objective is to scan product EAN codes without the need for using HTML input or textarea elements. The reasoni ...

managing information through the elimination of nested keys with node js / javascript

let json=[ { metadata: { tags: [] }, sys: { space: { sys: [Object] }, id: '4gSSbjCFEorYXqrgDIP2FA', type: 'Entry', }, fields: { richTextEditor: { 'fn-US': [Object] }, short: { 'as-ds': &a ...