Steps for selecting the data-link of a div using Selenium:

Take a look at this code:

<div class="results">

<div class="search-results" data-link="some url1">result1</div>
<div class="search-results" data-link="some url2">result2</div>
<div class="search-results" data-link="some url3">result3</div>
<div class="search-results" data-link="some url4">result4</div>


</div> 

This is a search bar where typing text displays results in a dropdown using AJAX.

The results shown above are links, but they do not have an <a> tag.

How can we click on one of these results (specifically the first result) if they do not have an <a> tag?

Answer №1

Give this a shot:

//div[@data-link="some url4"].click()

If that doesn't do the trick, consider this:

The data-link attribute is typically used in jQuery, making it difficult to provide specific guidance without access to the page source code. One approach is to inspect the scripts on the page and look for a click action that navigates to the link:

This script snippet may offer some insight:

<script type="text/javascript" language="javascript">
       $(".urllink").click(function (e) {

        var link = $(this).data("data-link");
        blabla

    });

</script>

Attempt to trigger a click event on the identified element from the script.

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

Sending a parameter value when onClick function is called

Currently, I am learning React JS and facing a challenge with passing parameters (like button ID or tab value) to the Tab onClick event. It appears that I'm receiving 'undefined' results when trying to pass attribute names as parameters. Ple ...

When utilizing a JQuery plugin for sliders, Dart does not function in the same way that traditional JavaScript does

Starting out with Dart for Front-End development has been a bit challenging for me. I am trying to incorporate a JQuery plugin called FlexSlider using the Js-Interop Dart Library. However, it's not functioning as expected compared to pure JavaScript, ...

Deriving worth from a JSON object

My JSON data structure has the following format: .... "location" : { "lat" : 37.42140090, "lng" : -122.08537010 }, .... I am having trouble accessing the lat and lng values. Any suggestions on how to do this? Cu ...

What are the steps to showcase a webcam stream in GLSL by leveraging Three.js?

One method of displaying a webcam video using ThreeJS involves creating a video texture, as shown below: video = document.getElementById( 'video' ); const texture = new THREE.VideoTexture( video ); texture.colorSpace = THREE.SRGBColorSpace; const ...

Guide to packaging TypeScript type declarations with an npm JavaScript library

I'm facing an issue with providing TypeScript type definitions for a JavaScript library. The library itself is written in TypeScript and transpiled by Babel, although this detail shouldn't affect the outcome. The problem lies in the fact that ne ...

How to Employ Javascript Set in a Mongoose SchemaType?

I am interested in implementing Javascript's Set feature in ES2015 as a SchemaType in Mongoose to take advantage of its uniqueness. However, I have run into an issue where the Mongoose documentation does not explicitly support Set, suggesting the use ...

The Selenium Python script fails to capture all of the visible data

Apologies for the misleading title, but I need help with a specific issue on a website I am trying to scrape: On the right side of the page, there is a "See all" text which, when clicked, reveals a list of links to different forks. My goal is to extract t ...

Display logo when website has been scrolled

On my website, I want to display a logo in the header only when the site has been scrolled. I attempted to accomplish this with JavaScript: if(document.getElementById("div").scrollTop != 0){ document.write("<img src='logo.jpg'>"); } How ...

Vanilla JavaScript - Conceal all remaining div elements

I have a situation where multiple divs are only visible after clicking a link. How can I ensure that when one div is clicked, all others are closed so that only the clicked one remains visible? Currently, I am using the following JavaScript: functio ...

Looking for assistance in presenting the value of a range slider on your webpage?

Greetings! I am facing an issue while trying to showcase the output of a slider through JavaScript. When I run the code, I encounter an error saying 'Cannot read property of null'. Below is the HTML code snippet: <div class='sliderContai ...

What could be causing the "document is not defined" error to appear in my code?

Currently, I am in the process of developing an application using React Native that allows users to input text, submit it by clicking a button, and then have the entered text sent to me via email. To achieve this functionality, I have utilized EmailJS and ...

Steps for disabling script debugger within Visual Studio 2013

How do I disable script debugging in Visual Studio 2013? I have already disabled script JIT debugging under Tools>Options>Debugging>JIT, and have turned off script debugging in Internet Explorer as well. Despite setting the error option to 'b ...

Guide to retrieving objects in React.js

Struggling to extract a country from an online JSON file that I am currently fetching. I am attempting to streamline the process by creating a function to retrieve the country from the dataset and avoid repeating code. However, I am encountering difficulti ...

Creating a TeeChart for HTML5 that combines both stacked and normal series can be done by following these steps

Hey there! I'm currently utilizing TeeChart for HTML5 and I'm wondering how to create a chart with both stacked and normal series. Specifically, I need two series to be stacked and a third one to remain unstacked (normal). I attempted to utilize ...

An error popped up out of the blue while attempting to execute Webpack

Looking to deploy my React website on IIS but encountering an error when running npm run build:prod. The error message states: index.js Line 1: Unexpected reserved word. You may need an appropriate loader to handle this file type. Below is the snippet fro ...

A warning message has been triggered: 'Script Alert Error - Object

I've been putting in hours on a SUP project that requires some tweaking and I keep running into the issue Script Alert Error: Object expected The code I've added is: $('#bottomOfStart_ScreenForm').before('<div style="display: ...

How to send information to a label on the same page with jQuery

I have a functional code that allows me to pass data to a div within the same page. However, instead of passing the data to a div, I would like to pass it to a label or textbox so that I can post it to the server. As someone who is new to ajax and jQuery, ...

Implementing Adaptive Images in Bootstrap 5 for a Specified Design

I am currently working on a website layout that involves displaying one image per section. My goal is to have the images positioned on either side of the text when viewed on a larger screen, as shown in the example below: https://i.sstatic.net/bms6S.png ...

React Full Calendar Error: Unable to access property 'calendar' from undefined

I'm encountering an issue while attempting to save selected time information in state. Any assistance would be greatly appreciated, thank you for your help! Please feel free to ask if more specific details are required. Below is a snippet of code fro ...

Is it possible for me to display dynamic content and utilize a template engine like (ejs)?

Currently, I am in the process of developing a weather application to enhance my skills with express and ejs. At the moment, I'm utilizing app.get to fetch data from darkSky's API successfully, and I can display it on my index.ejs page. My next ...