Activating autocomplete outcomes via AJAX using Cucumber/Capybara/Selenium

Whenever I try to run my tests, the autocomplete dropdown menu doesn't appear unless I physically click on the search input field.

This is a Cucumber test that utilizes Selenium Webdriver, and the data is sourced from the Crafty Clicks Address Autocomplete API.

I've experimented with various iterations of the same solution gathered from different posts and sources, all resembling something like this:

def fill_in_autocomplete(selector, value)
  page.execute_script("
    window.onload = function() {
      $('#{selector}').focus().val('#{value}').keydown();
    }
  ")
end

fill_in_autocomplete "#address_lookup", with: "EC2A 1AF"

I've also attempted more precise keydown-based solutions such as:

var e = jQuery.Event("keydown");
e.which = 50;
$("input").trigger(e);

Even after pausing the test and manually testing each solution in the console, none seem to work.

It's important to mention that I'm not utilizing jQuery UI, so any .autocomplete() solutions are not applicable here.

Throughout the process, I've used sleep at intervals to account for timing issues.

Unfortunately, I am at a loss for new ideas!

Answer №1

After encountering an issue with some recent versions of Firefox, I decided to find a solution that didn't involve downgrading the browser. Instead, I switched to using chromedriver and installed the convenient chromedriver-helper gem, which resolved all my issues seamlessly.

An interesting discovery during this process was realizing that trying to trigger focus on an input field in the Chrome console proved to be trickier than expected. It turns out that having the console open in Chrome prevents you from taking focus away from it. To overcome this obstacle, I had to devise a workaround by placing the focus code within a click event attached to a page element. By closing the console, clicking on the designated element, and shifting the focus to the autocomplete input field, I was able to successfully navigate through the testing process without any further complications.

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

Do something with the response data from the jQuery AJAX call when it is

<script> $(document).ready(function(e) { $('.username').change(function(e) { var usr = $('.username').val() if(usr.length >= 4) { $('#status').html('<font><image src="images/loader.gif" / ...

Is ngSwitch in Angular causing the label element to disappear?

I am using AngularJS to generate form elements dynamically based on an array containing form details such as input type and value. For example, here is the code snippet I have for creating a text input field: <div ng-repeat="input in input_array"> ...

Performing mathematical calculations with numerical values

This piece of code was created as a component of a calculator project for learning purposes. It functions correctly for the most part. However, I noticed that the addition operation seems to concatenate the two numbers together instead of actually adding ...

Simultaneously, two identical messages arrived in the form of push notifications via FCM

I have been working on implementing WebPush notifications using Vue.js and FCM. However, when testing the functionality, I am facing an issue where instead of receiving just one notification from Firebase, TWO IDENTICAL PUSH NOTIFICATIONS are being receive ...

Using unique headers with Phantomjs in Selenium WebDriver

As per the information provided here, it is now feasible to modify headers. Currently, I am attempting to adjust the Accept-Language in the PhantomJS webdriver. The code snippet below does not seem to be effective: DesiredCapabilities.PHANTOMJS['phan ...

Is there a way to automatically fill number fields by clicking on radio buttons using a JavaScript function?

Currently, I am facing an issue with a task that involves three elements: 1. Two Number fields (from standard class) that need to be populated dynamically. 2. A Javascript function designed to extract coordinates using geolocator. 3. A radio button which, ...

Show the cell data when the checkbox next to it is selected

I have a specific table setup and I am trying to display the content of the table cell if its corresponding checkbox is checked upon clicking a button. For example: If Row2 is checked, an alert box should display Row2 Below is my code snippet, Java ...

What causes certain images to have unspecified height and width measurements?

Currently, I am in the process of extracting image sizes from a website using a module called scraperjs. Most images have their height and width attributes defined, but some do not, resulting in the returned value being "undefined". How can I retrieve the ...

Clicking on "li" to activate and deactivate

Currently utilizing: $('#btnEmpresarial').attr('onclick','').unbind('click'); In order to deactivate a read using javascript.. However, I now require enabling the onclick after the function has completed. Is ther ...

What is the best way to retrieve information in an autosuggest textbox from a server or database?

I am looking for a way to modify my autosuggest textbox to fetch data from a server instead of a defined array. Can anyone provide guidance on how to achieve this? Here is the code snippet I am currently working with: HTML code- <!doctype html> &l ...

Remove all div elements that do not match the search results using jQuery

Need help with modifying results based on a search value across rows. For this example, let's use 90042 as the search value. Current JavaScript: (function($) { $(document).ajaxComplete(function(e, xhr, settings) { var zi ...

Error validation for jQuery div dropdown

Can jQuery validation be used to set the required attribute on a Bootstrap styled div dropdown instead of an option/select tag? The tags cannot be changed on this page, and there are multiple div dropdowns. <div class="btn-group"> <button typ ...

Adjust background color on click using JavaScript

Could someone provide me with the JavaScript code to change the background color of a page from blue to green when a button is clicked? I have seen this feature on many websites but haven't been able to write the code myself. I am specifically lo ...

resolving conflicts between Rails and JavaScript assets

Currently, I am facing an issue with two gems that provide JavaScript assets as they are conflicting with each other. The conflicting gems in question are the lazy_high_charts gem and the bootstrap-wysihtml5-rails gem. Initially, I only had the bootstrap ...

Locate the generated ID of the inserted child when saving the parent in MongoDB

If I have a document representing a post with comments like the one below: { "_id": "579a2a71f7b5455c28a7abcb", "title": "post 1", "link": "www.link1.com", "__v": 0, "comments": [ { "author": "Andy", "body": "Wis ...

Tips for Retrieving Information from Firebase in an Angular Application

I am facing an issue with my code where the ngFor directive is not working as expected when I use read_CheckOuts to return data from the database. Below are snippets of my code: crud.service.ts import { AngularFireDatabase} from '@angular/fire/datab ...

Filtering out duplicate names from an array of objects and then grouping them with separator IDs can be achieved using JavaScript

Imagine we have an array [ {id: 1, label: "Apple"}, {id: 2, label: "Orange"}, {id: 3, label: "Apple"}, {id: 4, label: "Banana"}, {id: 5, label: "Apple"} ] We want the output to be like this [ {id: 1~3~5, l ...

An unusual html element

During a recent exploration of a website's code using the inspect tool, I stumbled upon a tag that was completely unfamiliar to me. <gblockquote></gblockquote> I've come across a blockquote before, but never a gblockquote. Interest ...

Tips to prevent the return of undefined when a condition is not satisfied

I'm currently working on a react app and I have an array of objects (items) that I want to iterate over in order to display each object based on its index. I am using useState to set the index, which is updated when the user clicks a button. const ...

Transforming JSON data into an interactive table with HTML

After spending four days searching for a solution, I am still unable to figure out my problem. My goal is to convert a JSON string data retrieved from a URL into a dynamic table using JQuery and JavaScript. To achieve this, I need to load the JSON string ...