Obtaining the XPath for a data table containing two td elements that can be simultaneously clickable

<div class="dataTables_scrollBody" style="position: relative; overflow: auto; height: 370px; width: 100%; min-height: 0px;">
<table id="offer_create" class="display article-list ranklist_drag table table-bordered dataTable no-footer" aria-describedby="offer_create_info" role="grid" style="position: absolute; top: 0px; left: 0px; width: 100%;" width="100%" cellspacing="0">
<thead>
<tbody>
<tr class="odd" role="row">

    <td>test1</td>
    <td>test2</td>
</tr>

Is there a way to make the XPath and data in a data table clickable simultaneously?

For reference, here is an image showcasing how the data table should look:

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

Answer №1

WebDriver driver = new ChromeDriver();
WebElement tableElement = driver.findElement(By.xpath("//*[@id='content']/table[1]/tbody"));
List<WebElement> rows = tableElement.findElements(By.tagName("tr"));

for (int rowNum = 0; rowNum < rows.size(); rowNum++) {
    List<WebElement> columns = rows.get(rowNum).findElements(By.tagName("td"));
    System.out.println("Number of columns: " + columns.size());

    for (int colNum = 0; colNum < columns.size(); colNum++) {
        System.out.println(columns.get(colNum).getText());
    }
}

Note: <tr> denotes the row name and <th> signifies the column name in this code snippet.      

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

Wrapper Div at the Center

I'm currently working on aligning my webpage in the center using the following CSS: .wrapper { display: flex; align-items: stretch; background: #fafafa; /*max-width: 1520px; */ box-shadow: 1px 1px 12px rgba(0, 0, 0, 0.1); text ...

Clearing data validation in HTML after an error has been resolved.Is there a way to clear

I need some help with a cloud page I am creating. I have implemented an alphabetic data validation in HTML to only allow users to input letters, which is working as expected. However, the issue I am currently facing is that the data validation error messa ...

Setting the UTF-8 character encoding in Struts2

I am currently working on a JSP file where I collect form values and send them to a Struts 2 action class using jQuery Ajax. Here is what my Ajax function looks like: var DataValues = $("#Form1").serialize(); alert(DataValues); alert(decodeURI(Da ...

center a horizontal line using StyledSheets in your project

After drawing a horizontal line, I noticed that it is positioned towards the left side of the screen. I am hesitant to increase its width. Are there any other methods to move it to the center? I attempted wrapping it with another view and using alignConten ...

Add a class by utilizing the :class attribute

I reviewed the documentation, but I am still struggling to implement this in my project. Initially, I simply want to display a specific class using vue.js that I can later modify dynamically. I just need to establish the default behavior of that class, so ...

Do you think there might be an issue with the CSS coding?

I have designed a user-friendly responsive login form that allows users to easily log in and reset their passwords. However, I am facing an issue where the username and password fields are not displaying on separate lines as intended. I have thoroughly ins ...

Unable to use the same hexadecimal HTML entity in the value props of a React JSX component

Can someone explain why this code snippet displays dots as password and the other displays plain hexadecimal codes? <Field label="Password" value="&#x2022;&#x2022;&#x2022;&#x2022;&#x2022;" type="password" /> While this one disp ...

Tips for loading and updating data simultaneously in VUEJS from a single input

Currently, the data is displayed in a span tag with an input for updating it Is it possible to fetch data from an API, load it into an input field, update the input with new information, and send it back? What are the best approaches for achieving this? ...

Python and Selenium: What are the alternatives to "find_element_by" that would be suitable in this situation?

I'm new to using Selenium and I am trying to determine the best alternative to "find_element_by_..." in this specific case. <input _ngcontent-wsq-c70="" type="text" formcontrolname="username" onfocusrestaurantcolor="" class="form-control form-in ...

Display a notification when creating an activity is unsuccessful

I've been attempting to display a popup using the activity onCreate() method, but so far nothing is happening. There are no exceptions thrown and the popup isn't showing up. Here's the code snippet: protected void onCreate(Bundle savedInst ...

JavaScript and HTML are commonly used programming languages for developing

By utilizing JavaScript, I was able to generate a table dynamically based on user input. For example, if the user enters 3 and clicks "go", a table with 3 rows is created. Using the .keyup function allowed me to target a column successfully. However, an i ...

What could be causing the issue with HTML not being printed upon button click in ReactJS?

My goal is to display the word "Hello" on the screen when the add button is clicked. However, I am encountering an issue where it is not showing up. Any insights or solutions would be greatly appreciated! import React, { Component } from 'react'; ...

Avoiding the use of angle brackets in XSLT语

Looking to replace a sequence containing '.\s+\w+' with a line break This is what I currently have: <xsl:value-of select="replace($fdesc,'[.][ ]+\w+','<br/>')" /> However, I am encountering an er ...

Guide for executing two @Test methods within a single class file by utilizing WebDriver and TestNG

As I delve into the world of Web Driver, I encountered a piece of code that sparked my curiosity. Within this code snippet, there are two @Test methods residing in a single class that I am eager to run in parallel using testng.xml. Alas, a nagging questio ...

Is it possible to stack divs horizontally in a liquid layout while allowing one of the widths to be dynamic?

This is the code snippet and fiddle I am working with: http://jsfiddle.net/hehUt/2/ <div class="one"></div> <div class="two">text here text here text here text here text here text here text here text here text here text here text here te ...

What is the best way to delete HTML classes that were generated by a function?

Currently, I'm immersed in the Etch A Sketch project as part of my journey through The Odin Project. Using DOM manipulation, I successfully created a grid and displayed it on the screen. Now, my aim is to allow users to resize the grid by removing the ...

Retrieving the chosen option from a dropdown menu using AngularJS

<tr (click)="onRowClick(myDropDownList.value)"> <td> <select #myDropDownList (click)="$event.stopPropagation()" (change)="onChange($event.target.value)"> <option *ngFor="let n of numbers" [value]="n">{{n}}</option> </se ...

How can I fetch and reference multiple local JSON files in Vue using Axios?

I am currently utilizing vue for prototyping some HTML components. Is there a method to make Vue detect two separate JSON files? vue.js var vm = new Vue({ el: '#douglas-laing', data: { products: [], contentPanels: [] }, created() ...

"Transfer" the code within a Message Sending template

Although I am not well-versed in coding like many of you, I have been able to customize a free template to suit my needs. However, I am struggling with one aspect. When users submit their information on the contact form, I want their message and details to ...

Which web browser(s) can properly display the CSS property display: run-in?

Compatibility with IE7 and FF2.0 Suitable for IE8 and Opera 9+ Works only on IE7 Optimized for IE8 and FF3.5 Supports IE7 and Safari This question came up in a quiz, but I don't have all the browsers to test it. Any assistance would be greatly apprec ...