Tips for retrieving the value by reading and clicking on multiple identical href elements with the help of FindBy method using CSS

    <a href="test.aspx?id=1">TESTGOWN</a>
    <a href="test.aspx?id=2">TESTGOWN</a>

TESTGOWN can be found in various places on the page.

This particular section displays links.

@FindBy(how = How.CSS,using = "a[href='test.aspx']")

The link is not clickable.

CacheLookup

@FindBy(how = How.CSS,using = "a[href='test.aspx']")
    WebElement gownlink;

    public void ClickDress()
    {
        System.out.println("gownlink"+gownlink);
        gownlink.click();

    }

CALLING CODE:

Dashboardpage= PageFactory.initElements(driver, DashboardPage.class);
Dashboardpage.ClickDress();

ERROR: Marionette INFO New connections will no longer be accepted

Answer №1

In the scenario you described,

TESTDRESS can be located in different areas on the page
. However, during the HTML formatting process, the id of the parent node and the <span> tags were removed. Assuming that the href attributes are unique for each node, the following approach should be effective:

@FindBy(how = How.CSS,using = "a[href='test.aspx?id=1']")
@CacheLookup
WebElement testlink;

public void ClickDress()
{
    System.out.println("testlink"+testlink);
    testlink.click();

}

and

@FindBy(how = How.CSS,using = "a[href='test.aspx?id=2']")
@CacheLookup
WebElement testlink;

public void ClickDress()
{
    System.out.println("testlink"+testlink);
    testlink.click();

}

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

How can you catch a Selenium WebDriver exception in the Python Interactive Window of Visual Studio Code?

I encountered an unexpected Selenium exception known as NoSuchElementException even though I had included a try-except block in my code. Below is a streamlined version of the code, with the stack trace showing that the Exception was triggered by the WebDri ...

The CSS variables set within the :root section of styles.scss are not recognized as valid

Trying to implement global colors using CSS variables in my Angular 11 app. The styles.scss file contains: :root{ --primary : #0b68e8; --secondary:#ABCFFF; } .test-class{ background: var(--primary); } However, when applying this class in one ...

Oracle database encounters a lock while updating a table

My application is encountering an issue when performing a simple table update: UPDATE TABLE SET COLUMN = 'XYZ' WHERE PK = 123 The problem arises when Hibernate attempts to execute the update, resulting in the table getting locked with an ORA ev ...

The art of Python's conditional statements and logic

I am new to using Selenium and Python, and I am trying to grasp the concept of conditional statements. However, it seems that my code is not taking the second condition into consideration: What I am attempting to do: https://i.stack.imgur.com/oFqjQ.png ...

DIV collapsing in reverse order from the bottom to the top

Looking for some help on how to create two links that, when clicked, will scroll a hidden <div> up to fill the full height of its parent container. I've been having trouble with the element using the full height of the <BODY> instead. ...

Inquiring about the presentation of text using HTML and CSS

I am looking for a simple fix to make a line of HTML display exactly as follows: 22 West Washngton St. Northbrook, IL 39492 Instead of: 22 West Washington St. Northbrook, IL 39492 Can someone guide me on how to remove the space between the lines of ...

Tips for linking random information with objects in Java

I'm currently utilizing naga for handling asynchronous socket programming. Nevertheless, I find myself in need of a way to attach arbitrary data to the Socket objects. For example, my code looks like this: service = new NIOService(); // Server is J ...

Click X button to toggle and close the dropdown menu

After successfully creating a responsive menu that toggles with a hamburger icon at 1205px resolution, I encountered an issue. Once the hamburger icon is clicked and the dropdown menu opens, there seems to be no way to close it. I am looking to add an X bu ...

XPath in Selenium for accessing data within a carousel

When running the script below, I expect it to display a list of car names. I suspect that the issue lies in how I am referencing the carousel element. from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.we ...

A guide to deserializing a Map in Java with keys as integers

I've encountered an issue while using the Flexjson API for serializing and deserializing a map with integer keys. When deserializing, the keys are automatically converted to strings. Is there a way to preserve the keys as integers? Below is an exampl ...

CSS :contains selector after adding a script through Ajax append operation

Is there a way to change the text color in $('td:contains("text")').css('color','red') after an Ajax load script? Here is the main code snippet <div id="datatable"></div> <script src="https://code.jquery.com/j ...

Set a variable to represent a color for the background styling in CSS

My goal is to create an application that allows users to change the background color of a button and then copy the CSS code with the new background color from the <style> tags. To achieve this, I am utilizing a color picker tool from . I believe I ...

Different ways to restrict Table Header to 2 lines using CSS

When it comes to limiting text to a specific width, using white-space:nowrap is usually the go-to solution. However, I am facing a unique challenge where I need to make sure my header text fits within a specific width. I initially tried adding individual ...

Exploring Tomcat 9's capabilities with web socket demonstrations

Compiling the Tomcat examples, specifically the echo endpoint.java, has been a challenge for me. Upon searching in the /WEB-INF/classes folder, I found an echoendpoint.class file which seems precompiled in the tomcat9 zip file as I wasn't able to comp ...

Using Bootstrap in Rails: Positioning a dropup to align with another element in a footer

I am attempting to align the content as a footer, but having trouble with the dropup not lining up properly: <footer class="footer"> <div class="container-fluid"> <div class="row"> <div class="col-xs-12 col-sm-12 col-md-12"> &l ...

Is there a way to manipulate the direction of bouncing divs using a button?

I want to design a single button that can control the bouncing motion of my div elements. The initial configuration will have the space divs arranged in a static, straight line. Once the button is clicked, the divs should start bouncing within their conta ...

What is the best way to customize a button component's className when importing it into another component?

Looking to customize a button based on the specific page it's imported on? Let's dive into my button component code: import React from "react"; import "./Button.css"; export interface Props { // List of props here } // Button component def ...

Resolving the problem with iterating through $list using SCSS/SASS @mixin

Consider the following list: $box-shadow-properties: -webkit-box-shadow, -moz-box-shadow, box-shadow; I am attempting to create a mixin that iterates through this list: @mixin box-shadow-with-inset($box-shadow-params, $inset-params) { @each $property ...

Trigger javascript function after clicking on two buttons

I am currently working on developing a web game inspired by Duolingo. In a specific scenario, I need a function to be triggered after two button clicks to progress further. However, I am facing challenges in finding solutions online or understanding it on ...

Sync HTML Videos

Issue: I am currently developing a 3 column layout where certain columns need to remain sticky at the top of the viewport. In one section, I want to use the same video as a background for all 3 columns, with the specific effect of having the middle column ...