what is the best method to locate a parent element containing a particular child using By.xpath()?

In the past few days, I've been utilizing the selenium-webdriver in nodejs for web scraping. However, I am facing an issue on how to locate an element that contains a specific child element.

I have attempted to use the following operator but it does not yield the desired results:

By.xPath("tr[contains(@class, 'datetime2')]")

Please see the HTML snippet below:

<table>
  <tbody>
    <tr style="bacrgound-color:#eee">
      <td class="datetime2">
        20:00
      </td>
    <tr>
    
    <tr></tr>
    
    <tr style="bacrgound-color:#eee">
      <td class="datetime2">
        21:00
      </td>
    <tr>
    
    <tr style="bacrgound-color:#eee">
      <td class="datetime2">
        22:00
      </td>
    <tr>
    
    <tr></tr>
  </tbody>
</table>

My goal is to locate only the 'tr' elements that include the <td class="datetime2"> element and ignore the empty <tr></tr> elements.

Could someone please assist me in finding this element using the By.xpath() function?

Answer №1

you can experiment with this alternative x-path approach.

//tr[not(td[@class='datetime'])]

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 day of the week should Twilio choose for their event?

While using Twilio, I have come up with a straightforward solution to play an audio file when receiving a call. However, I now want to customize it so that different Mp3 files are played depending on the day of the week. For example, playing the first Mp3 ...

utilizing Java with Selenium WebDriver to manage web tables

<table class="footable table table-hover table-striped table-bordered" cellspacing="0" cellpadding="6" border="0"> <thead> <tr class="CartBlueHeader"> <th align="10%">PNR No</th> <th width="23%" al ...

Trying to execute Python scripts in Selenium IDE as a test suite

I'm facing a couple of issues when trying to run multiple Python test scripts exported by the Selenium IDE Python Remote Control plugin formatter. 1) The browser window automatically closes after a python script is completed. I am using Firefox for m ...

Transforming a REST API get call into GraphQL

I'm currently using a REST API that accepts a code parameter, searches the database for matches, returns results if the parameter exists, and redirects users to a long_url retrieved from the database. How can I convert this functionality to GraphQL? i ...

What is the reason for allowing and disregarding multiple root paths in Node's path.resolve function?

As per the documentation provided by Node.js, the function path.resolve operates in a specific manner: The paths provided are processed from right to left, with each subsequent path being added until an absolute path is formed. For example, if we consid ...

Switch the type and version of the browser using Selenium

In an attempt to change my user agent using the Selenium Webdriver, I have utilized the following code. However, it has come to my attention that Google Analytics is able to easily detect my browser and its version (specifically Firefox 54.0 in this case). ...

The StreamingTextResponse feature is malfunctioning in the live environment

When I share my code, it's an API route in Next.js. In development mode, everything works as expected. However, in production, the response appears to be static instead of dynamic. It seems like only one part of the data is being sent. I'm puzzl ...

Selenium is having difficulty detecting XPATH expressions

Hey everyone, I'm currently working with Selenium WebDriver to extract values from a drop-down list. However, I am facing an issue as my code seems unable to recognize the xpath I provided. Here is the code snippet I am dealing with: WebElement se ...

Having trouble with uploading files to AWS S3 through Lambda

My goal is to upload files to S3 using Lambda functions. The code I am working with scrapes data from the web and creates a CSV file. The original code (without AWS, just scraping and creating CSV) has been tested and works fine. I made slight modificatio ...

Warning: MaxListenersExceededNotification may occur during the installation or creation of Node.js projects on macOS

Encountering a warning message while attempting to set up or generate Node.js projects on macOS (darwin): (node:80101) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [TLSSocket]. Use emitter.setMaxList ...

Setting up a project in TypeScript with Angular 2(+) and a Node/Express server is essential for successful

Searching for the optimal approach for a project similar to this: An Angular 2 (4) client coded in TypeScript A Node/Express backend also written in TypeScript Utilizing some shared (TypeScript) models accessible to both client and server code. Is it pr ...

Unable to locate the addEventListener function when utilizing php webdriver and selenium

I have been working with the webdriver for just three weeks now, and I've come across an issue regarding finding addEventListener. My setup includes using the selenium standalone server in combination with a PHP framework developed by Facebook. My g ...

What is the best way to incorporate Sikuli with Selenium in Python?

I am familiar with using Sikuli in Java, but now I have Python code that automates a web application and I want to incorporate Sikuli into it. Despite extensive searching on the Internet for information on how to use Sikuli in Python, I have not found any ...

Encountering an error in Nodejs where it is unable to access the properties of an object due to it being undefined

Hello, I am currently working on creating a todo app using Node and Express. The frontend is functioning correctly, but I'm encountering an error in the terminal. Despite passing the todo object, it is displaying 'id' as undefined. Here is ...

The error message "app.listen is not a function" is indicating that there

I am encountering an issue while trying to start my server from the www file. The error message I receive is as follows. Can anyone help me understand why this error is occurring? The version of Express I am using is 4.16. Could it be related to a problem ...

ChromeDriverService and Azure Pipelines Agents

Currently, I am automating Selenium tests in an Azure DevOps pipeline using C#. To improve debugging, I recently updated my code to include ChromeDriver logs, requiring me to make changes to utilize the ChromeDriverService. string binaryDir = Manag ...

Unable to Delete Record Using Jquery and Express in 'DELETE' Request

While working on my api using node/express and jquery, I encountered an issue where my DELETE requests are not functioning as expected. JQUERY: $('.formula-body').on('click', function (e) { if (e.target.className == 'fa-trash- ...

I am having trouble with searching for places using the Google API in my Node

Recently, I've been working on integrating the Google Maps API places feature into my project. Thankfully, I came across an npm module that simplifies the process of connecting it to node. Check out the npm module here! After downloading the module ...

Express.js is stuck in a continuous loading loop due to an error occurring within the generator

I have observed that when there is an error within a generator, express.js continues processing without halting, making it difficult to identify the specific error. My query is: how can I stop express.js and display the error message whenever there is an e ...

The Express GET route does not support parameters or additional paths

I am facing an issue with making a fetch request when trying to add additional path or parameters... Here is what I want to achieve: const fetchOwnerCardList = () => { fetch("http://localhost:5000/api/card/ownerCards", { method: "GET", header ...