How can I navigate to column 3 of an HTML table using XPATH with Selenium Webdriver in Python?

I have extracted the text from the Name column of an HTML table using XPATH, which corresponds to column index [1]. Now, I need to navigate to the 3rd column with index [3] using XPATH, but I'm not sure how to proceed.

Here is my current XPATH:

//table[@id="analysis_reports_ct_fields_body"]//span[contains(text(), "Matches")]

In the HTML snippet provided below, the text "View" is located in the 3rd column. However, I cannot rely on the text "View" as it is sometimes blank.

The HTML snippet:

<table id="analysis_reports_ct_fields_body" cellspacing="0" style="table-layout: fixed; width: 100%;">
   <colgroup>
      <tbody>
         <tr class="GLKP2TGBFG" __gwt_subrow="0" __gwt_row="0">
            <td class="GLKP2TGBEG GLKP2TGBGG GLKP2TGBHG">
            ...
            </td>
            <td class="GLKP2TGBEG GLKP2TGBGG">
               ...
            </td>
            <td class="GLKP2TGBEG GLKP2TGBGG">
               ...
            </td>
            ...
         </tr>
         ...
      </tbody>
   </table>

When I use the XPATH below, it highlights various sections of the table:

//table[@id="analysis_reports_ct_fields_body"]//span[contains(text(), "Matches")]//ancestor::div

Is there a way to utilize the ancestor axis to reach the 3rd column? I attempted using //descendant::*, but it did not highlight anything. I believed that descendant moves down the tree, while ancestor moves up.

//table[@id="analysis_reports_ct_fields_body"]//span[contains(text(), "Matches")]//descendant::*

In my method, I will have a parameter called Name (representing column 1 of the table where "Matches" is found), and from there, I aim to locate the 3rd column within the table.

Best Regards, Riaz

Answer №1

Below is an example of an Xpath that can be utilized.

//table[@id='analysis_reports_ct_fields_body']//td[.//span[contains(text(), 'Matches')]]/following-sibling::td[2]

This specific Xpath is designed to locate a td element within a table that includes a span element with the text "Matches", then moves to the second adjacent sibling (which corresponds to column 3). By utilizing this Xpath, the process of navigating through the DOM structure is streamlined and made more efficient.

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

Dealing with online captchas while using WebDriver

Calculate: 1+7 = A webpage features a user input text box where you can enter the sum of two numbers. We need to correctly identify these two numbers, such as 1 and 7. The values entered in this location can vary. I appreciate any assistance with this ta ...

What are some ways to enhance the opacity of a Material UI backdrop?

I'm looking to enhance the darkness of the material UI backdrop as its default appearance is not very dark. My goal is to make it dimmer and closer to black in color. ...

Tips for making a scrollable container that allows its contents to overflow without clipping?

Currently working on implementing a horizontal card row for my website with a unique hover effect - the cards lightly rotate and raise on hover. Here is a preview: https://i.sstatic.net/eDQ59.gif To make this row responsive, I added overflow-x: auto; to e ...

gallery showcasing pictures with a prominent main image and accompanying smaller images

I am struggling to display my image gallery the way I envision it. I would like to have a larger main image with the rest of the images displayed on the right side below it. The current code I have is: <div class="gallery"> <a href=" ...

Being required to design a distinct div for every article I am extracting from the API

In the midst of developing a website for my college project, I have successfully configured my news API to pull and display data using JavaScript. Currently, I am faced with the challenge of having to create separate div elements each time I want to add n ...

Modify the font style of numbers based on the keyboard language selected by the user

Is it possible to change the font family of numbers in input fields based on the user's keyboard language? For example, if the user is typing in Persian, the numbers should be displayed in a Persian font, and when they switch to an English keyboard, t ...

Trim the edge of a dynamic picture

Currently, I am facing a challenge with an image that requires the corner to be cut off. The image needs to be responsive in order to adjust its size according to the page dimensions. Since the image is managed by a CMS, the corner cut has to be done progr ...

`How can you effectively manage Site Guard on your Drupal website using Selenium?`

I'm facing a challenge on the Drupal dev website with Site Guard integration. Whenever I try to automate actions using Selenium, it prompts for Site Guard credentials each time. I've tried treating it as a regular alert but that approach doesn&ap ...

Struggling to troubleshoot this issue with Python Selenium Chromedriver. Help needed!

from selenium import webdriver from selenium.webdriver.common.keys import Keys import os Game_Pin = input('Please input your PIN: ') NickNAME = input('Please input your nickname: ') def Enter_Press(): browser.find_element_by_name( ...

Having difficulty with utilizing winapp

I am having trouble executing the code capabilities.setCapability("app", "C:\\Windows\\System32\\calc.exe"); CalculatorSession = new IOSDriver(new URL("http://127.0.0.1:4723"), capabilities); Although this code is supposed ...

"Discovering the most striking image with Beautiful Soup: How to

from bs4 import BeautifulSoup as bs from selenium import webdriver driver= webdriver.Chrome(executable_path=CHROME_PATH) driver.get('https://www.childrensalon.com/artesania-granlei-blue-knit-dungaree-shorts-set-313840.html') soup = bs(driver.pag ...

Utilizing Python and Selenium to automate the selection of a checkbox on Google Chrome

I have searched through several discussions where a similar issue was raised, but unfortunately none of the suggested solutions seem to work for me. My goal is to select/click a checkbox using Chrome. Here is the HTML code: <table cellspacing="1" cell ...

Styling and Div Container management with Bootstrap in ASP.NET Code Behind

I am currently in the process of developing an ASP.NET application that requires the dynamic creation of "TextBox" and "DropdownList" controls. Here is the method I have been using to create "TextBox" controls: private void CreateTextBox(string id, string ...

"Encountered an issue with locating elements using the driver.find_element

I need assistance in automating the process of clicking on the "Create New Network" button using Selenium. <button type="button" id="dt-refreshBtn" class="btn wc-btn--link" data-label="Create New Network" role=&q ...

Enabling clipboard functionality in Python through Selenium

When attempting to copy and paste content from an online webpage using Python Selenium, I run into issues with clipboard read access permission pop ups. View Pop-up Image Is there a way to handle this by adjusting Chrome options to allow clipboard access ...

Column reverse flex-direction is functioning correctly, however, it is imperative that it does not automatically scroll to the bottom

I have a Flexbox set up where I need the contents to display in reverse order. Everything is working well, but the list has many items and the newest ones are appearing at the top. Currently, the Flexbox automatically scrolls to the bottom, but I want it t ...

Choosing a dropdown list element in Selenium using custom optionsLearn to pick a dropdown

What is the method to choose a custom dropdown list item using Selenium? I need to pick a country from the dropdown list by utilizing Selenium with Python WebDriver. <select id="id_country" class="hidden-field" name="country" data-id="1394114974464-fO ...

An irritating bug causing a 1px difference in Chrome 21

Hey there, I've encountered a strange issue with the datepicker on this website. It works perfectly fine on IE8+, Firefox 14, Chrome 20, and Opera 12. However, as soon as Chrome updated to version 21, things went haywire! I'm baffled and can&apos ...

When the class is not present, simply scroll to the specified div

Having trouble getting the jQuery scroll to function properly in the following code snippet. Essentially, I want to display a button named #checking when the class k.state-disabled is not active. After the button is displayed for the first time, I aim to ...

Is there a way to remove the scrollbar from the menu created with react-burger-menu?

How can I remove the scroll bar from the menu created with react-burger-menu? Despite trying various CSS properties adjustments, I have not been able to achieve the desired effect. Here is an image of the open menu and the corresponding CSS: (https://i.st ...