Grab cell information from a dynamic table using Ruby and Selenium

I am attempting to retrieve a property of cells within a table.

<table id="m-103" class="m-row" cellspacing="0">
<a name="2"></a>
<table id="m-108" class="m-row " cellspacing="0">
<a name="3"></a>
<table id="m-191" class="m-row " cellspacing="0">
 <tbody>
   <tr>
    <td class="m-st">
    <td class="m-jk m-N">
    </td>
</td>
</tr>
</tbody>
</table>

Here is the xpath I currently have

 .//*[@class='m-row']/tbody/tr/td[@class='m-jk']

However, this only accesses the cells in the first table.

  1. I am specifically looking for the m-N class value. Not every table contains the m-N value. Is there a method to only examine tables that include "m-N" or do I need to individually inspect each one? I am only aware of navigating to specific paths, so I am unsure how to iterate through each table.

  2. How can I retrieve the second class value "m-N"? Every CSS or xpath I have tried has been unsuccessful, and they are all specific to a predefined table.

I came across a solution where the person was using jQuery. Should I consider learning and utilizing jQuery in addition to Ruby and Selenium?

How to get the second class name from element?

There are numerous tables, but I only showcased 3 for this example. Additionally, the quantity of tables and cells varies frequently.

Answer №1

In order to retrieve the td elements that have a class attribute containing the value m-N, you can utilize the xpath function contains(). Give this a try:

"//td[contains(@class, 'm-N')]"

If the situation becomes more intricate with other classes also containing 'm-N' such as 'm-Nx', then you will need to adjust your approach like this:

"//td[contains(concat( ' ', @class, ' '), ' m-N ' )]"

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

What is the best way to create a sliding menu that appears from the right side on a mobile device using HTML, CSS, and JQuery

Is there a way to have the menu slide in smoothly from the right side after clicking on the menu bar icon, including sliding the menu bar icon itself? The current code displays the menu directly upon clicking on the menu bar, but I would like it to slide i ...

The scroll bar will be automatically reset once the content inside is updated by using the $selector.html() function

I am looking to create a dynamic scrollable content feature. Initially, I retrieve the data and set the content as follows: $("#sub_menu li").on("click", function () { $("#gallery").html(get_html($(this).attr("id"))); $("#gallery").cs ...

Creating a PDF with Python Selenium and prompting for a file name before saving

I need help with saving a website as a PDF file using the printing dialog. My current code successfully saves the page as a PDF, but it requires me to manually input a filename when prompted, which I am struggling with. Below is the code snippet: import ...

Creating a dynamic CSS animation with multiple spans for typing effect

I have made some progress with this project. Here is the link to what I have so far: http://codepen.io/tacrossman/pen/GJglH However, my goal is to have the cursor blinking animation running after each new word (span) is written out. When I attempt to ad ...

"Font-face is effective in Internet Explorer but appears to have compatibility issues in Firefox particularly regarding font formats

I have downloaded a free font that comes in regular and bold variations, with the following formats: svg, eot, ttf, woff. These fonts display properly in Internet Explorer, but they are not working in Firefox. 1. I would like to understand which format is ...

problem with custom scroll bars on Chrome and Internet Explorer

Below is the URL for the designated folder The vertical scroll bar is functioning properly across all browsers on my personal computer, however, it appears to be malfunctioning on Chrome and IE of a select few other devices. I conducted a test on a machi ...

The challenge of handling overflow in IE9

I'm encountering an issue specifically in IE9 where a child div is not respecting the overflow:hidden property of its container div. The outlined blue div in the image represents the container with overflow:hidden. The goal is for the images to stay w ...

What is the current importance of CSS3 vendor prefixes?

I've been pondering the importance of specifying vendor prefixes like 'webkit', 'moz', 'ms' or 'o' in modern CSS. It seems that Opera has switched to Webkit, meaning we may no longer need '-o-'. IE10 e ...

Delivering seamless css integration using express.js

Lately, I've been struggling with serving CSS using Express.js. After some trial and error, I managed to make it work. However, I'm puzzled as to why my new code works while the old one doesn't. Here's the code that now works for me: co ...

Joomla CSS styling malfunctioning

I've been exploring the creation of an in line menu using Joomla 1.6 and CSS. The issue arises when Joomla removes <span class="dmenu"> from the document before saving, despite having all cleanup options turned off. This led me to try a couple ...

Unlock the power of Component level CSS in NextJS with this simple guide!

I don't have much experience with CSS, as I rarely write it these days due to the popularity of libraries like MUI. However, I recently found myself in a tricky situation where I needed to rewrite this example Emabla carousel in typescript and NextJS. ...

What is the reason for CSS to be included in the installation process when running npm install with [someLibraryName

After executing the following command: npm install vue-material I noticed that it installed and replaced some of the css styles in my application, leading to conflicts. To resolve this issue, I had to manually search for the specific piece of css and ove ...

Guide to extracting content from child Text Nodes using Selenium

My goal is to extract "I give you €0.00." from the code snippet provided below. After inspecting it in Developer tools, I found that the following xpath can target the required element: //*[@id="windowID"]/text()[2] However, when using Selenium to ...

Creating an arrow line with CSS styling can be achieved easily

In order to create a horizontal line with a breakdown in the middle that displays an arrow, I want to use only HTML and CSS without relying on bitmap images. If needed, Font Awesome can be used to achieve the desired result. It's important for me to h ...

CSS styles are combined and included at the beginning of the index.html file

During the creation of a production version of my Angular 9.0.4 application, I noticed that the CSS is bundled and placed at the top of the dist/index.html file as shown below: <link rel="stylesheet" href="styles.6ea28d52542acb20a4c6.css"><!docty ...

Tips for selecting the unchosen option from the dropdown menu

How can I extract the values that were not selected in the drop-down menu? Assistance is greatly appreciated. ...

Include a triangle shape at the top of a div container that has a background image using CSS

Struggling to add a point or triangle shape to my div with a background image, finding it difficult to create enough open space. This is the desired outcome: https://i.sstatic.net/LZVaF.png This is what I have implemented so far: <div class="bg"> ...

The button remains in a pressed state when viewed on a mobile device

This button is functioning properly in desktop view, but in mobile view the button remains pressed down. :root { --green: #4285f4; --black: rgba(9, 13, 25, 0.752); --box-shadow: .4rem .4rem 1rem #ccc, -.4rem -.4rem 1rem #fff; --box-shadow-inset: ...

How can I customize the color of the border/background on my jquery menu?

I have been using the jquery function menu() to generate a menu, and it's working as expected. However, there is one aspect that I would like to customize: the white border around the menu button should be black instead. You can see what I mean by ...

Adding text and buttons to the initial image in the slider: a step-by-step guide

I'm facing an issue with my html image slider as I try to add buttons and text to the first image but it keeps getting overridden. <div id="captioned-gallery"> <figure class="slider"> <figure> & ...