Choosing an option from a dropdown menu does not trigger the execution of an AngularJS function through Selenium

Currently, I am attempting to create a Selenium test that involves selecting an item from 2 dropdown menus and then clicking a button. However, I have encountered an issue where the second dropdown menu is populated based on an angularjs call depending on the selection made in the first dropdown. Strangely, the angular call fails to execute when the value changes, resulting in the second list not being populated and causing an error. Why does the angularjs call fail to run when the value changes?

Here's a snippet of the dropdown:

<select id="itemList" style="width:495px;" onchange="angular.element($(this)).scope().itemChanged(this);">
   <option value="item1">Item 1</option>
   <option value="item2">Item 2</option>
   <option value="item3">Item 3</option>
</select>

Selenium script:

SelectElement item = new SelectElement(driver.FindElement(By.Id("itemList")));
item.SelectByText("Item 2");

Although the code successfully selects an item from the first dropdown, the angular call responsible for populating the second dropdown fails to execute. How can I ensure that this call runs as expected?

Answer №1

Attempting to activate this trigger through selenium will not work if it is not being triggered properly (after a click, selection, or other action). Consider using JavaScript to force the trigger instead. I suggest trying the click() method over the select method.

Answer №2

One way I resolved this issue was by manually initiating the onchange() event that triggered the angular function once the initial dropdown was filled.

I utilized the IJavaScriptExecutor interface in my code to execute a script which simulated a change event on the element with id "itemList".
IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
jse.ExecuteScript("$(arguments[0]).change();", driver.FindElement(By.Id("itemList")));

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

Kurento's WebRTC feature is currently experiencing difficulties with recording functionality

Currently, I am attempting to capture video using the Kurento Media Server with nodejs. Following the hello-world example provided here, I connected a recorderEndpoint to the webrtcEndpoint and successfully got everything up and running. However, on the se ...

Troubleshooting problems with the CSS code for a progress bar in Gmail

I recently came across a unique progress bar design on Gmail and wanted to implement something similar. I found some code snippets on this webpage: . However, I encountered an issue where the progress bar was only displaying in Internet Explorer but not in ...

Employing JavaScript to set a variable that changes dynamically

In my code, I have a functionality that allows for changing different dropdowns with similar ending IDs. In other parts of the code, I have assigned variables rl and rl_extra as well as rs and rs_extra. Now, when the var prefix is determined to be either ...

How can I generate codegen types using typeDefs?

I have been exploring the capabilities of graphql-codegen to automatically generate TypeScript types from my GraphQL type definitions. However, I encountered an issue where I received the following error message: Failed to load schema from code file " ...

Trouble with Sound during Quickblox Webrtc Audio Calls

I am having an issue with my audio calls. When I make a call to another user, everything seems fine except that I cannot hear any sound when speaking into the microphone. I am only interested in making audio calls. The call is initiated by pressing a butt ...

Retrieve the number of rows in the table component

I'm in need of getting the row count from a table component that I have built using vuejs. My goal is to display the row count outside of the table component structure. The issue with the code snippet below is that it doesn't show the correct row ...

Create an excel spreadsheet using HTML tables with the help of jQuery

Upon clicking a button, I aim to generate an excel sheet. Essentially, I am trying to achieve what is being discussed here (Kalle H. Väravas answer). If the following links are not working within Mozilla browser, then maybe my code requires ActiveXObject ...

Error: React Component not rendering correctly - Element Type Invalid

React Uncaught Error: Element type is invalid Encountering a problem in my React application where the following error message appears: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite compone ...

Communication between React.js and Node.js in VS Code

I recently started learning React and node js. I managed to create a simple "Hello World" project in reactjs, which works perfectly. App.js import React, { Component } from 'react'; import logo from './logo.svg'; import './App.cs ...

Exploring the Depths of Web Scraping: A Guide to Scraping Within a Scraped Website

I have successfully scraped data from a specific page, but now I need to follow another href link in order to gather more information for that particular item. The problem is, I am unsure of how to do this. Here is an excerpt of what I have accomplished s ...

Ways to send a JSON object to a Node.js server

I am working on developing a hybrid mobile application with Node.js as the backend and MongoDB for saving data. My server is functioning properly, and I have set up routes to handle user requests. While I can retrieve data from my server using the GET met ...

The function to send keys cannot be called on a primitive type of void

As someone who is new to selenium, I am in the process of implementing a data-driven framework using page factory. However, I keep encountering the following error: Cannot invoke sendKeys(String) on the primitive type void This error occurs when attemp ...

Discovering if an agent is a mobile device in Next.js

I am currently working with nextjs version 10.1.3. Below is the function I am using: import React, {useEffect, useState} from "react"; const useCheckMobileScreen = () => { if (typeof window !== "undefined"){ const [widt ...

Is there a way for me to either fulfill a promise or face failure?

Currently, I am working on creating a Thennable function that may return a promise based on its parameters. However, there is a possibility that the parameters are invalid which would require breaking the promise chain with something unexpected. What can b ...

Error: Firebase Cloud Functions reference issue with FCM

Error Encountered An error occurred with the message: ReferenceError: functions is not defined at Object. (C:\Users\CROWDE~1\AppData\Local\Temp\fbfn_9612Si4u8URDRCrr\index.js:5:21) at Module._compile (modul ...

What is the best method for extracting specific information from a JSON dataset (API) when using Axios in ReactJS?

Is there a way to retrieve an image from the Instagram graph API that contains specific text in the caption and display it on the homepage? I am having trouble implementing this rule using promises in axios. Any help would be greatly appreciated. import ...

Removing the Login button from the layout page after the user has logged in can be achieved by

I am currently developing an MVC application in Visual Studio 2012. Within my layout page, there is a login button that I would like to hide after the user successfully logs in. Despite my attempts, the method I am using doesn't seem to be working. Ca ...

Configuring Firefox Preferences for Selenium to Set Download Location in Python

My approach to extracting web data involves utilizing Selenium Marrionette and GeckoDriver. I employ the following code snippet to configure my Firefox profile preferences: fp = webdriver.FirefoxProfile() fp.set_preference("browser.download.folderList", 1 ...

Dynamically changing the borders of WebGL canvases: a guide to adding and

Here is my code snippet for creating an HTML canvas: <canvas id="glCanvas" class="canvases" width="20" height="20></canvas> To set the color, I am using the following: gl.clearColor(0.0, 0.0, 0.0, 1.0); gl.clear(gl.COLOR_BUFFER_BIT); I am w ...

Transmit information from node.js to the frontend utilizing only raw JavaScript

Seeking guidance on sending data object from a Node.js server to a JS file for frontend use. In the main.js file, DOM manipulation is performed. The following request is made: let dataName = []; let request = async ('http://localhost:3000/') =& ...