What is the process for identifying the relative x path of a distinctive code?

There are 3 matching nodes with the same source code which is causing the failure:

//img[(@src='/PHYLINSPortlet/images/override-0.gif')]

<img id="_PHYLINSPortlet_WAR_PHYLINSPortlet_INSTANCE_o3P5_:form_PolicyContent_UI2:Messages:0:j_id1885:0:j_id897" class="null" alt="" src="/PHYLINSPortlet/images/override-0.gif" style="border:0px"/>

This represents the xpath of a dynamic button:

https://i.stack.imgur.com/Ou6Xk.png

The task at hand is to click on all these buttons.

The approach taken was as follows:

List<WebElement> buttons = driver.findElements(By.xpath("//img[(@src='/PHYLINSPortlet/images/override-0.gif')]"));
for( WebElement button : buttons ) {
    button.click();
}

Answer №1

Finding a solution for your issue is a bit challenging without having access to your HTML code.

Based on the image provided in your query, it appears that there are three identical images and you need to click on a specific one, such as the SECOND image. To achieve this, you can utilize xpath methods like following-sibling or preceding-sibling to create a unique xpath.

For instance, if you have a distinct column in your table (e.g., Rule id) or you wish to select a particular image, such as rule id Val01014, you can use the following xpath methods:

//img[@src='/PHYLINSPortlet/images/override-0.gif']/preceding-sibling::td[text()='Val_01014']

OR

//img[@src='/PHYLINSPortlet/images/override-0.gif']/following-sibling::td[text()='Val_01014']

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

Finding specific text within an element in Selenium using Java, even when the text is partly variable

Looking for the counts of Requeues, App Exits, and Greets Started in the following element. I will also need to validate the counts for each event. <div _ngcontent-ome-c213="" class="counts"> 0 Requeues<br _ngcontent-ome-c213=& ...

Tips for choosing multiple rows from various locations in a table with Selenium WebDriver

I have been experimenting with the following code to retrieve table rows, but I want to specifically select rows that are in various locations within the table. @Test public void testRowSelectionUsingControlKey() { List selectedRows = ...

implementing automated testing with selenium webdriver in multiple languages

Currently, I am developing an automation project that needs to accommodate multiple languages. My main concern is how to efficiently verify all the text strings on pages like the dashboard without making the test cases too lengthy. I have already set up a ...

Error in Java Selenium: Element not found due to webpage not being fully loaded

I'm currently working on automating tasks for Amazon. When I search for "laptop" on the website, I attempt to choose the "Apple" brand, but I encounter a "no such element" error. Upon manual inspection of the element, I notice it is located as follows ...

The process of retrieving values from disabled inputs in webdriver

Here is the HTML code: <input id="txtPortalLogin" class="form-control input-sm" type="text" disabled="disabled" placeholder="No Link" value=""/> I need help with extracting values from a disabled field. Refer to the attached screenshot to see which ...

Having trouble interacting with the 'button' in selenium webdriver using Java

In this code snippet, I am trying to pinpoint the location of an href button: <a class="btn grey-edit" data-original-title="Login" data-placement="top" data-toggle="tooltip" href="/users/userlogin/3"> <i class="fa fa-sign-in" aria-hidden="true"& ...

selenium webdriver causing undead processes

I am currently in the process of setting up a test suite for internal and potentially external (production) use, to replace pingdom. However, I am encountering an issue where every other time I attempt to run it as a Java Application in Eclipse, the progra ...

Start Node-Red and use the Selenium driver

Running mocha test suite to test a node-red nodes involves using mocha and the selenium driver. I encountered an issue while running the node-red module. When I start the test with $ mocha --ui **tdd**, the node-red application is unable to locate my flow ...

Please do not attempt to switch to the window until it is fully open

Experiencing an issue with my tests where I encounter no frame exceptions and Out of bounds exception after selecting a button and switching to the window that opens. Here is my code snippet: clickWithActions(driver, launchNote); sleepForTi ...

Designing a user-friendly graphical interface (GUI) for the

I am interested in developing a user interface for this script that can automatically download PDF files. However, I am uncertain about where to begin. There are two specific input fields that require modification. drp.select_by_visible_text('**Dan Pi ...

I encountered an issue: AttributeError - 'WebElement' object does not possess the attribute 'sendkeys'

On my practice page, I have the following code: from selenium import webdriver driver = webdriver.Chrome(executable_path="G:\Selenium Testing\Drivers\chromedriver.exe") driver.get("https://rahulshettyacademy.com/AutomationPrac ...

Is it possible to navigate to a hostile iframe using Python Selenium Webdriver?

Encountering an issue while attempting to switch_to_frame() or switch_to.frame() (by the way, which one is correct?) on a troublesome iFrame. Should this functionality be supported? def click_all(driver): for img in imgs: img.click() ifram ...

What is the best method for determining the specific child element selected when using xpath?

Let's consider an example with the following XML structure: <tr> <th>LION</th> <th>TIGER</th> <th>CHEETAH</th> <th>GIRAFFE</th> <th>BEAR</th> </tr> If I wanted to select th ...

Tips for finding the element in an iframe using Python with Selenium WebDriver

During my automation testing on the website , I encountered difficulty locating a specific element with Selenium. The element in question is the search bar located at the top of the page, used for searching stocks. My goal is to locate this element and in ...

Hold off on executing two tasks - selenium using Java

I am attempting to utilize Fluent wait for performing two specific actions: Clicking on the search button Verifying the result for a particular element Currently, I am using the following code snippet but it does not seem to be functioning as expected: ...

Selenium for Ruby: Creating a unique custom scroller by scrolling down

I am trying to retrieve data that is displayed after I scroll a custom scrollbar within a website, not just the typical scrolling function. It seems like Selenium is unable to locate this information without performing the scrolling action first. I have ...

A guide on running category-based tests in TeamCity using MSTest

I encountered an issue when attempting to run vstest using mstest in TeamCity with the following assemblies list: Z:\Test\Tests\bin\Debug\Test.dll /category:"abc Tests" This error occurred during the vstest execution with mstest i ...

What is the method for handling user input using Selenium WebDriver in Python?

I attempted to locate this input using selenium in order to test a login, but I have been unsuccessful in finding it. The code is written in python and I made several attempts as documented below: Most of the comments were notes on the different methods I ...

Even in the implementation of find_element(By.XPATH, value='xpath_value'), NoSuchElementException may still manifest

Objective: Extracting movie titles from and converting them into a list. The provided code: driver = webdriver.Chrome() driver.get('https://www.boxofficemojo.com/chart/top_lifetime_gross/?ref_=bo_cso_ac') xpath = '//td[@class="a-text ...

Create a new JSON file and add data using ObjectMapper

My current project involves delving into Jackson to gain a better understanding of how it works. I am in the process of creating a simple program that can both read from and write to a file, specifically storing JSON data in it. This project revolves aroun ...