Discovering the dimensions of a disabled attribute within a table using XPath in Selenium with Java

I'm attempting to determine the number of columns in a specific table, but some are disabled - I'd like to know if it's possible to get the count without including the disabled ones (only counting the visible columns).

As you can see in the image attached, certain tds are disabled.

The command I've tried using is:

driver.findElements(By.xpath("//*/table[@id='TABLE NAME]/tbody/tr[2]/td[@style='display:none;']")).size()

The issue is that the style='display:none;' may not work for future tables if the value for disabled tds differs. Thank you in advance.

Answer №1

If you want to only select the elements that are visible, you can achieve this by using a combination of not and contains in your XPath query:

driver.findElements(By.xpath("id('table-id')/tbody/tr[2]/td[not(contains(@style,'display:none'))]")).size()

Alternatively, you can also use a CSS selector to achieve the same result:

driver.findElements(By.cssSelector("#table-id > tbody > tr:nth-child(2) > td:not([style*='display:none'])")).size()

Another approach is to filter out the elements that are not displayed by utilizing the WebElement::isDisplayed method:

driver.findElements(By.cssSelector("#table-id > tbody > tr:nth-child(2) > td"))
  .stream().filter(WebElement::isDisplayed).count()

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

Css technique for changing color on mouse hover

I currently have a social media bar on my website with icons for Facebook, Twitter, Google+, and RSS. Here is how it looks: When I hover over the icons, I want the circle around the image to change color to blue. However, every attempt I've made end ...

What is the most effective approach to seamlessly conceal and reveal a button with the assistance

I have two buttons, one for play and one for pause. <td> <?php if($service['ue_status'] == "RUNNING"){ $hideMe = 'd-none'; } ?> <a href="#" class="btn btn-warning ...

Can object-fit be preserved while applying a CSS transform?

Currently, I am developing a component that involves transitioning an image from a specific starting position and scale to an end position and scale in order to fill the screen. This transition is achieved through a CSS transform animation on translate and ...

Selenium was unable to locate the element by its name or ID

While using Selenium to log in to my MathWorks account, I encountered the following error message: "AttributeError: 'NoneType' object has no attribute 'send_keys'." Below are the source links for the login page of MathWorks: and I ha ...

Issue: In the Selenium Java Eclipse environment, there is an error indicating that the variable "Driver"

Currently, I am in the process of familiarizing myself with Selenium for automated testing. I have managed to successfully complete all parts of the test case except for the final step which involves checking if an alert is present to confirm the transacti ...

Executing selenium xvfb on ubuntu 11.04

I am currently attempting to run a selenium test using maven on an Ubuntu system. Below is the Maven configuration I have set up: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>selenium-maven-plugin</artifactI ...

What steps do I need to take to design a menu?

I need assistance in organizing my menu with submenus. The code I currently have successfully retrieves all the submenus, but I would like to categorize them accordingly: For instance: Main Menu - Submenu 1, Submenu 2, Submenu 3 How can I go about categ ...

What is the significance of using flexGrow in the parent div of a Material UI grid?

I am currently working on understanding a code example located at https://codesandbox.io/s/9rvlm which originates from the Material UI documentation (https://material-ui.com/components/grid/): import React from 'react'; import PropTypes from &ap ...

An error occurred in Selenium WebDriver, causing an Exception to be thrown in the main thread with the message: "org.openqa.selenium.ElementNotInter

Experiment Scenario: Attempting to capture and evaluate Gmail Login functionality. Current Result: Upon running the WebDriver code, a Mozilla browser instance is launched. Although the username is successfully entered, the password field remains unfilled. ...

What is the best way to showcase a half star rating in my custom angular star rating example?

component.ts import { Component } from '@angular/core'; @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { projectRating ...

Instructions on creating a Superfish menu with a vertical layout in the first level and a horizontal layout in the second level

Currently, I am using the Superfish menu in Drupal7 and have designed my first item level to be vertical. However, I now want to style my second item level horizontally. I have tried various CSS approaches and added some class names via jQuery like $(&apo ...

What could be causing the malfunction of Bootstrap Multiselect functionality?

I have been attempting to set up Bootstrap Multiselect but it simply refuses to work. Despite trying various solutions, I am unable to pinpoint the issue. My index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

Assign a value to a jQuery variable from user input

Can someone assist me in setting an input field to the value of a jQuery variable? I am encountering difficulties with this task. My aim is to have equipment failure counts appear in an input textbox so that I can later write the value back to a table. Eac ...

What is the best 'event' to pair with an <input/> element in iOS/Android development?

Looking for a way to toggle results when a user starts typing in a search field? Here are some event options: mousedown / mouseup touchstart / touchend focus You could also consider using the "change" event instead of "click" to check for text input an ...

Utilizing a pre-existing Google Chrome profile with the Selenium Chrome WebDriver in Python

I'm having trouble loading my complete existing Google Chrome profile with all extensions, where I am logged into both Google and other site accounts. The code seems to have a syntax error that I can't pinpoint. chrome_options = Options() chrome ...

Widget for navigating through Youtube videos

I am currently working on creating a widget that allows users to navigate a YouTube video using buttons. For instance, if the video is of a car race, there would be buttons labeled Lap 1, Lap 2, and so forth. My idea involves adding an extension to the vi ...

What is a more efficient method for generating HTML code using PHP variables?

My online store showcases a variety of products, each housed in a div with the id content block. The link, image, background, description, and price for each product are all retrieved from a mySQL table. Initially, I planned to store the HTML code below as ...

How to Use PHP to Submit Form Information

I am a beginner in PHP and I need help with sending form details to an email address. I have tried looking for solutions online but I keep running into the same issue - when I submit the form, it downloads the PHP file instead of sending an email. Below i ...

Creating a tab component using vanilla javascript

I am facing an issue with my tab component in plain JavaScript. The content displays correctly in debug mode, but after compilation, it does not show up on the browser. Additionally, when I select a tab, the 'activeNav' class is applied to indica ...

Convert JSON objects within an array into HTML format

Is there a way to reformat an array of JSON objects that has the following structure? [{"amount":3,"name":"Coca-Cola"},{"amount":3,"name":"Rib Eye"}] The desired output in plain HTML text would be: 3 - Coca-Cola 3 - Rib Eye What is the best approach to ...