[英]how to get the size of disabled attribute in table with xpath in selenium-java
I am trying to get the amount of columns in a specific table, but there are disabled attribute - and i would like to know if it is possible to get the size of it without the disabled ones(the amount of the displayed columns in the table). 我正在尝试获取特定表中的列数量,但是有禁用的属性-我想知道是否有可能在没有禁用的属性的情况下获取它的大小(表中显示的列的数量)。
as you can see some of the tds are disabled in the attached picture. 如您所见,附图中的某些tds已禁用。 The command i tried to work with 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;'
问题是style='display:none;'
might not work in future tables because the value will be different for disabled tds. 可能在将来的表中不起作用,因为对于禁用的tds,该值将有所不同。 Thanks in advance. 提前致谢。
To return the visible ones, you could use not
and contains
in your XPath: 要返回可见的内容,可以在XPath中使用not
和contains
:
driver.findElements(By.xpath("id('table-id')/tbody/tr[2]/td[not(contains(@style,'display:none'))]")).size()
Or with a CSS selector: 或使用CSS选择器:
driver.findElements(By.cssSelector("#table-id > tbody > tr:nth-child(2) > td:not([style*='display:none'])")).size()
Another way would be to filter all the elements with WebElement::isDisplayed
: 另一种方法是使用WebElement::isDisplayed
过滤所有元素:
driver.findElements(By.cssSelector("#table-id > tbody > tr:nth-child(2) > td"))
.stream().filter(WebElement::isDisplayed).count()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.