Choosing an item from a dropdown menu that is not built with the Select function in Puppeteer

In our project, we have implemented a drop down feature using React AntD design which does not utilize the Select tag. You can find an example of this implementation here.

https://i.sstatic.net/pRG1m.png

The options for the drop down are generated using ul and li tags, as depicted in the image below -

https://i.sstatic.net/eKalM.png

I am looking to understand how one can handle or select a specific option using an index with this type of drop down menu.

In case of using Select, one can typically employ the page.select() method, as indicated in this Stack Overflow discussion found here. However, attempting this method did not result in a successful selection from this unique drop down.

An alternative approach I tried involved utilizing page.keyboard.type('ArrowDown') and page.keyboard.type('Enter') to simulate key presses for navigation within the drop down menu. Unfortunately, this resulted in a

TypeError: (intermediate value) is not a function
error.

Answer №1

If you want to utilize the dropdown functionality using the provided link, start by clicking on the dropdown link to display the list of options.

Next, you can interact with a specific item in the dropdown menu by its index:

await page.evaluate(() => {
  const dropdown_link = document.querySelector('#components-dropdown-demo-trigger .ant-dropdown-link');

  dropdown_link.click();

  const dropdown_menu_item_links = document.querySelectorAll('.ant-dropdown > .ant-dropdown-menu > .ant-dropdown-menu-item > a');

  dropdown_menu_item_links[0].click(); // Select Menu Item Link by Index
});

Answer №2

To effectively interact with the page elements, it is recommended to use the page.click method. In this scenario, you can utilize the code snippet

page.click('div.ant-dropdown.ant-dropdown-placement-bottomleft')
. Although the selector is lengthy, having an ID would simplify the process.

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

Retrieving the value of a selected radio button in Asp.net using Javascript

I have searched for a solution to my issue multiple times, but none of the solutions I have found seem to work for me. I am currently working with IE. <asp:RadioButtonList ID="rbtnView" runat="server" OnSelectedIndexChanged="rbtnView_SelectedIndexChan ...

Getting rid of the backslash from a JSON object in an Axios POST request

Question regarding adding a reverse slash to a JSON file when making an Axios post request. Despite using the replace function, the backslash remains in the final output. axios .post( "https://test-manager/backend", { ...

preclude any dates prior to the chosen date

I need a solution for a scenario where I have 5 datepickers in sequence. When I select a date on the first picker, all previous dates should be disabled when selecting on the next picker. Additionally, once a date is selected on one picker, the following ...

Utilizing a Grunt task to inject code into an AngularJS file

Hey there! I'm currently looking for a way to add some code into my app.js file that will only execute when I run the "grunt serve" task. This code is just two lines of javascript that should be present when I test the app on my local environment. Unf ...

Having difficulty with loading images lazily in a jQuery Mobile app with LazyLoadXT feature

Struggling to incorporate lazy loading in my jQM app with Lazy Load XT v1.0.6. Oddly, images only appear when switching browser tabs, not while scrolling down. This happens on Firefox and Chrome. <img src="/img/default-img.jpg" data-src="/img/product/ ...

jquery selector to target an element nested inside an anchor tag

Is there a way to use a Jquery selector to extract the text content within the 'name' attribute? <a href="page1.php" id='title' name="<?php echo $res['id'];?>" title="<?php echo $res['title'];?>" < ...

Placing a JavaScript button directly below the content it interacts with

I am currently working on a button that expands a div and displays content upon clicking. I am facing an issue where I want the button to always be positioned at the bottom of the div, instead of at the top as it is now, but moving it within the parent div ...

Encountering TypeScript error TS2345 while attempting to reject a Promise with an error

I recently encountered a perplexing TypeScript error message that I am struggling to comprehend. The specific error reads as follows: error TS2345: Argument of type '(error: Error) => void | Promise' is not assignable to parameter of type & ...

What is the best way to transfer a PHP string to JavaScript/JQuery for use in a function?

Within my PHP code, I have the following: $welcome = "Welcome!"; echo '<script type="text/javascript">addName();</script>'; Additionally, in my HTML/script portion: <a id="franBTN"></a> <script type="text/javascript ...

Loading of iframes occurs only after receiving the content sent through the postMessage function

I have a scenario where an iframe is used to receive information through the contentWindow.postMessage function in order to log in to a page that I am creating. However, I am facing an issue where the page loads before the contentWindow.postMessage message ...

Having trouble executing a JavaScript function correctly when using an onclick event created within innerHTML in JavaScript

My goal is to trigger the loadInWhat function with an onclick event and populate my input field with id="what" using the value of LI function createDivBox(data){ document.getElementById("whatContainer").style.display="block"; document.get ...

Rotate the cylinder according to the normal vector of the tube endpoint

I'm working on creating a curved 3D arrow using three.js. My approach involves using a Tube along a curved path and a Cone shaped cylinder. Here's how they currently look: https://i.sstatic.net/jmVB6.png https://i.sstatic.net/P756z.png My goal ...

Ways to troubleshoot NPM installation issues related to gyp ERR

I have tried most of the suggestions found online, but I am still encountering an error when trying to install opencv and serialport. My current setup includes Visual Studio 2019 with C++ Desktop environment and Python 3.7. npm ERR! command C:\Windows ...

Retrieving key-value pairs from an array of JSON objects

How can I access key-value pairs in JavaScript if the JSON file is formatted like this: [[{"field":"name","message":"Insert name!"},{"field":"surname","message":"Insert surname!"},{"field":"email","message":"Insert email"}]]; The current solution seems ...

Building a stylish table using Material UI in ReactJS

I've been working on creating a dashboard using the Material UI minimized table. You can check out the documentation here: Material UI Tables However, I've encountered an issue that has me stuck for the past 5 hours. While I was able to successf ...

React functional components can utilize switch cases for conditional logic

I am attempting to create a multi-step form using a switch case, but for some reason, changing the state with nextPrev does not update the case. export const FormSteps = ({items, pending}) => { const [step, setStep] = useState (2) const nextS ...

Deactivating a form field depending on a selected radio button in Angular 2

If I have two radio buttons, with a click function called localClick for the first button to give value 1 and the second button to give value 2. <div class="ui-g-12"><p-radioButton name="group1" value="Local" (click)=localClick(1) label="Local"&g ...

Errors are being thrown by 'npm run serve' due to the absence of FilterService

I've been working on a project using Vue.js and I keep running into an issue with npm. Every time I install it, I get errors saying that certain files are missing from the node_modules folder. When I try to run npm run serve, I encounter the followin ...

How to use jQuery to dynamically add a variable to a request in Laravel 5.2

Is it feasible to append a variable to the Laravel cookie in the client using jQuery? Understandably, the Cookie is linked to the request during GET? Can you include a variable in the $request container in Laravel 5.2 using jQuery before initiating a GET ...

Exploring the Angular search scope for data

I am working on creating a function that will search my scope for the value of status and return true if it matches 1. Below is the array I am using for this task: "review": { "currentStep": 7, "stepA": { "status": 0, }, "stepB": { ...