Choosing img tag titles or alts within td elements using Selenium in C#

In my current setup, there is a table with five columns. The fifth column contains an image icon that changes randomly based on backend data. This image does not have a static id or class.

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

The CSS for this setup looks like this:

https://i.sstatic.net/7PK3y.png

Using the code below, I was able to extract the text from column #4:

var temp = driverIE.FindElement
(By.XPath("//td[@class ='af_column_cell-text OraTableBorder1111'][4]"))
                    .GetAttribute("innerText");

I then attempted to retrieve the alt or title attributes of the image tag in column #5, but it returned null:

var temp = driverIE.FindElement
(By.XPath("//td[@class ='af_column_cell-text OraTableBorder1111'][5]/img"))
                    .GetAttribute("alt");

My goal is to store the value of either the title or alt attribute in a temporary variable, and based on its value, redirect control to a different method.

Answer №1

Utilize the Chrome developer tools once more. Locate your element using the arrow tool, then access the right-click context menu to select Copy XPath.

Answer №2

To those encountering this issue, here is the solution.

Initial Code:

var temp = driverIE.FindElement
(By.XPath("//td[@class ='af_column_cell-text OraTableBorder1111'][5]/img"))
                    .GetAttribute("alt");

Updated Code:

var temp = driverIE.FindElement
(By.XPath("//td[@class ='af_column_cell-text OraTableBorder1111'][5]//img"))
                    .GetAttribute("alt");

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

Creating a carousel similar to the one on Skipperlimited's website can be achieved

I am working on a project and I would like to create a design similar to the one found at Specifically, I am interested in replicating the carousel of images and the rotating carousel within their logo. Can anyone provide guidance or suggestions on how to ...

Selenium on Sauce Labs does not successfully load the page in Firefox after clicking

An issue has arisen where a test that functions properly with selenium webdriver locally is timing out when executed remotely on saucelabs.com. Notably, the test runs smoothly for Chrome in both local and remote scenarios. The problem seems to lie in the ...

Use the angular cli to incorporate the CSS styles found in the node_modules directory

After successfully installing a new library with npm, I now face the challenge of importing the CSS into my project. It seems unwise to directly link to the node_modules folder. Can anyone suggest an easy way to import this CSS into my Angular CLI project? ...

Updating JQuery function after window is resized

click here Currently, I am using slick-slider to showcase content in 3 columns by utilizing flexbox. The aim is to have the slider activated only on mobile view. This means that when the screen size shrinks down to mobile view, the 3 column flexbox transf ...

Tips on adding style to your jQuery autocomplete dropdown

I am currently utilizing jQuery autocomplete functionality. I have configured it to communicate with a service and retrieve records: <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1 ...

Guide to converting a nested JSON object into a primitive type using the field of one of the nested objects

Consider the following JSON data: [{ "id": 123, "description": "test", "group": { "id": 456, "description": "org" } }] I am looking to deserialize the JObject into a C# object. Typically, I would approach it like this (whe ...

Managing two variables in C# Controller and View

I am facing an issue with the two variables in my controller class. The first variable, currentUserId, is supposed to store the user currently logged into the website. The second variable, currentRoomId, should track the chat room the user is in. The probl ...

Create a relative xpath expression that targets every item in the list

I am currently utilizing the website for my project. Within this site, I am specifically using Demo table 2 as a reference point. My main goal is to create an xpath that will extract the list of details found in the structure column of a Web table and dis ...

Converting CSS to LESS with multiple classes sharing the same properties: step-by-step guide

I have some CSS code here that I'd like to convert into LESS format. Can you help me with that? .A .B h4, .A .B h4 a, .A .C h4, .A .C h4 a, .D h4, .D h4 a { color: #345e8a !important; display: inline-block; font-family: @font-family-sans ...

What's the best way to rearrange Bootstrap cards from a horizontal layout to a vertical layout for improved responsiveness?

I'm currently working with Bootstrap to align two cards horizontally, but I also want to ensure that mobile users can view the cards stacked in a column layout. I've experimented with adding 'flex-direction' in combination with the @med ...

Effortlessly find data in an HTML table and showcase the results instantly without

I am looking for a way to implement search functionality in my table without refreshing the page. The fields above the table are used for searching and I want the results to be displayed within the same table. Here is an example of the code: <?php $for ...

Ways to initiate a CSS transition without hovering over it

Currently, I have a sidebar that is hidden and only shows up when the mouse hovers over it. I'm wondering how I can make the CSS transition trigger before the mouse hover, similar to what happens in this sidebar link: . Any advice on how to achieve th ...

Bidirectional Data Binding in .NET Blazor Utilizing a Handler Method within the Parent Component

Attempting to incorporate two-way data binding in Blazor (.Net 8). The new way, as per the documentation, is to use @bind:get/@bind:set. Here is a solution that is functioning perfectly: https://i.sstatic.net/NnVOp.png @* Components\Pages\Home.r ...

selenium.common.exceptions.WebDriverException: Issue with GeckoDriver: The executable for 'Mozilla Firefox' may be experiencing incorrect permissions

Struggling with getting selenium to work properly with browsers. As a complete beginner, I tried running the application as an administrator based on recommendations, but it didn't resolve the issue. Below is my code snippet along with the error messa ...

Expand the <canvas> element to completely fill the flex item without any scrollbars

I am currently utilizing Bootstrap 5 and experimenting with setting up a nested flex layout that occupies the entire window. One of the flex items should be filled by a "stretchy" canvas element, ensuring there are no scrollbars present. However, when I a ...

The horizontal overflow in the HTML code was unsuccessful

I stumbled upon an interesting issue where I applied a div with specific styling: overflow-x: scroll However, the outcome was not as expected. Instead of overflowing, the content simply started on a new line. Here is the source code for reference: & ...

Understanding the Select MethodThe process of choosing the most

I'm just starting out with Java and Selenium, trying to expand my knowledge. I'm currently facing a challenge in extracting names from a Dropdown Menu using the Select class. To tackle this issue, I've set up a String Array variable with th ...

Having trouble with CSS messing up your gridview button display?

Oddly enough, whenever I place buttons inside a gridview, they end up looking very small (as shown in the image below), even though the gridview itself has no CSS applied to it. Is it possible that some other CSS is affecting the buttons? I have too much ...

Implementing a Jquery check based on a checkbox

Hey, I'm having an issue with a condition. When I uncheck the checkbox, it doesn't uncheck. I've tried to make a block display, but the JavaScript isn't working. I attempted to add: document.getElementById("Reload").style.display = "b ...

Having issues with clicking or selecting the value shown in the dropdown menu

I need some help with implementing code using Selenium Webdriver in Java. My website has a text box where users can enter the first letter and an AJAX value will be displayed. I want to select a specific value by sending keys to the text box. WebElement ...