Tips for locating the XPath to select an image with matching names

Could someone provide me with the XPath to click on the image <img> associated with "TM100" mentioned in the td tag?

I am having difficulty selecting the image because they all have the same xpath.

<tr>
<td>
<div id='xxx' class='avatar_standalone' ...>
<div class ='yyy'>
<div class ='zzz'>
<a oncontextmenu="return false" href="javascript:void(0)" onclick="xxx('MINE|XX0172', '2');>
<img class="newassetIcon assetIcon linkable" src="https://xxxx/servlet/servlet.ImageServer?id=015d00000020ZaWAAU&oid=00Dd0000000eu33&lastMod=1377179945000"/>
</a>
<span class="imgData" style="display: none;">MINE|XX0172</span>
</div>
</div>
</div>
</td>
<td style="border: 1px solid rgb(211, 211, 211);">XX0172</td>
<td style="border: 1px solid rgb(211, 211, 211); text-align: center;">6073.7</td>
<td style="border: 1px solid rgb(211, 211, 211);">TM2</td>
</tr>

<tr>
<td>
<div id='xxx' class='avatar_standalone' ...>
<div class ='yyy'>
<div class ='zzz'>
<a oncontextmenu="return false" href="javascript:void(0)" onclick="xxx('MINE|XX0172', '2');>
<img class="newassetIcon assetIcon linkable" src="https://xxxx/servlet/servlet.ImageServer?id=015d00000020ZaWAAU&oid=00Dd0000000eu33&lastMod=1377179945000"/>
</a>
<span class="imgData" style="display: none;">MINE|XX0172</span>
</div>
</div>
</div>
</td>
<td style="border: 1px solid rgb(211, 211, 211);">XX0172</td>
<td style="border: 1px solid rgb(211, 211, 211); text-align: center;">1073.7</td>
<td style="border: 1px solid rgb(211, 211, 211);">TM3</td>
</tr>

<tr>
<td>
<div id='xxx' class='avatar_standalone' ...>
<div class ='yyy'>
<div class ='zzz'>
<a oncontextmenu="return false" href="javascript:void(0)" onclick="xxx('MINE|XX0172', '2');>
<img class="newassetIcon assetIcon linkable" src="https://xxxx/servlet/servlet.ImageServer?id=015d00000020ZaWAAU&oid=00Dd0000000eu33&lastMod=1377179945000"/>
</a>
<span class="imgData" style="display: none;">MINE|XX0172</span>
</div>
</div>
</div>
</td>
<td style="border: 1px solid rgb(211, 211, 211);">XX0172</td>
<td style="border: 1px solid rgb(211, 211, 211); text-align: center;">8073.7</td>
<td style="border: 1px solid rgb(211, 211, 211);">TM100</td>
</tr>

Answer №1

Give this a try, it might be the solution you're looking for:

//tr[descendant::td[contains(text(),'TM100')]]//img[@class='newassetIcon assetIcon linkable']

I have conducted thorough testing with the code provided above using the following:

//tr[descendant::td[contains(text(),'TM100')]]//td[contains(text(),'XX0172')]

Answer №2

To retrieve the img element, you can utilize the XPath below:

//tr[td = 'TM100']/div[@id = 'xxx']/div[@class = 'yyy']/div[@class = 'zzz']/a/img

If your intention is to click on the image, it would be ideal to target the a element as shown here:

//tr[td = 'TM100']/div[@id = 'xxx']/div[@class = 'yyy']/div[@class = 'zzz']/a

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

WebDriverWait with 34? (Rust Selenium)

Is it possible to wait for a specific URL change in the thirtyfour crate for Rust, similar to Selenium for Python and Java? Java example: new WebDriverWait(driver, 20).Until(ExpectedConditions.UrlToBe("my-url")); Instead of an existing function ...

Setting up ZAP for Selenium testing

I am currently in the process of configuring OWASP ZAP to function alongside my selenium tests. public class ZapScanTest { static Logger log = Logger.getLogger(ZapScanTest.class.getName()); private final static String ZAP_PROXYHOST = "127.0.0.1"; private ...

Generate a distinct report folder for every execution by utilizing Selenium-Cucumber Maven

I'm currently utilizing extent reporting in my selenium-cucumber project to generate report files. However, each time the program runs, it overwrites the previously generated report. Is there a way to create separate report folders with timestamps app ...

Cells within a table are equivalent

I am attempting to ensure that all table cells match the size of the image, but for some reason, they are not aligning properly. Visit this link for reference. Here is a condensed version of the HTML code: <table> <tr> <td> ...

Achieve seamless transitions between animations when hovering with CSS3

I am facing an issue with an element that has a CSS3 animation. When the element is hovered over, the animation changes to another infinite one. While everything is functioning correctly, the transition between animations sometimes feels too abrupt and b ...

Unidentified event listener

I am currently facing an issue where I keep getting the error message "addEventListerner of null" even though I have added a window.onload function. The page loads fine initially but then the error reoccurs, indicating that the eventListener is null. Str ...

The hidden DIV containing an ASP.NET CheckBox consistently yields a value of false

I have a group of form elements located within a hidden div which looks like this: <div id="jDivUpdateFolder" style="display:none;"> <asp:TextBox ID="txtEditFolderName" runat="server"></asp:TextBox><br /> <asp:TextBox ID ...

Struggling with combining CSS stylesheets?

I am looking to incorporate the vertical timeline feature from CodyHouse into a project utilizing a Bootstrap template hosted on Github. I have successfully transferred the HTML content, however, there are some complications with the CSS files. The issues ...

A guide to locating elements based on text without considering capitalization with Selenium and Xpath

I am currently working with Java version "1.8.0_191" and Selenium 3.141.59. My goal is to determine if a page contains the words "error" or "erreur", regardless of case sensitivity. Locating the text is simple: List<WebElement> elementList = drive ...

Creating a responsive design for mobile apps in Ionic using CSS

I need help with making my Ionic app responsive across all mobile devices. The design on the page was created using CSS, but it is not displaying properly on every device. How can I ensure that it adapts to different screen sizes? <template> <Io ...

ng-html-bind for a label with a checkbox

Currently, I have a view that uses the standard bootstrap layout for checkboxes. In this layout, the input is located within the label tag. <div class="checkbox"> <label ng-bind-html="vm.trustedHtml"> <input type="checkbox" ng- ...

What is the best way to add a hover effect to two different objects simultaneously?

I am facing an issue with two div's, A and B. I want to hover over DIV A and display DIV B without hiding it when moving the mouse from DIV B. <div id="a"><img src="images...." class="profile" id="options" /></div> <div id="b"> ...

Issue with rendering <li> elements in Firefox browser detected

I have been working on a website and encountered an issue with the display of list elements in Firefox. The list is not showing consistently in Firefox, but it appears fine in IE, Opera, and Safari. I have attached an image below showing the difference bet ...

An error occurred in Selenium WebDriver, causing an Exception to be thrown in the main thread with the message: "org.openqa.selenium.ElementNotInter

Experiment Scenario: Attempting to capture and evaluate Gmail Login functionality. Current Result: Upon running the WebDriver code, a Mozilla browser instance is launched. Although the username is successfully entered, the password field remains unfilled. ...

What is the best way to update a specific section of my website by modifying the URL while keeping the menus fixed and the site functioning smoothly?

I am in desperate need of assistance as I search for a solution. Currently, I am working on a project involving music within a web browser or application. My goal is to utilize HTML, PHP, JS, and CSS to create this project. If I start with a website, I p ...

Using ng-class directive with condition in AngularJS

Here is a unique pop-up that allows users to encode item information. https://i.sstatic.net/sn9QZ.png I need to implement a feature where, if both the Foreign Currency and Conversion Rate fields have values, the Amount should be calculated by multiplying ...

Error message: Unable to access the state property of an undefined object

I've been attempting to integrate a react sticky header into my stepper component. However, I've encountered an issue where it doesn't render when added inside my App.js file. As a result, I've started debugging the code within App.js ...

Difficulty encountered with altering background color of table row in Firefox using CSS

I'm facing an issue with styling table rows that have alternating classes - I want to highlight the row that is being hovered on using CSS. Below is the CSS code I have implemented: .gridrowclass1 { background-color : #bbb00b } .gridrowclass1:h ...

In my ejs file, I need to input a name and then process it in my post request

I am working on an ejs file where I need the user to input their username into a form. I will then use this username in a .get request to perform certain logic. However, I am encountering an issue where the username is showing up as undefined. Here is a s ...

Seeking assistance to transfer div elements into a different div post an onclick event

I have a container that contains four separate divs. My goal is to append the remaining three divs to another specific div after clicking on one of them. Does anyone know how I can achieve this? <!DOCTYPE html> <html lang="en"> < ...