通过多个类名来查找div元素? [英] Find div element by multiple class names?
本文介绍了通过多个类名来查找div元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< div class =value test/>
我想标识那个web元素。它只有这两个类定义。
我不能这样做,因为 className
不接受空格分隔值。什么是替代方案?
<div class="value test" />
I'd like to identify that web element. It only has this two classes defined.
I cannot do the following as className
does not take a space separated value. What are alternatives?
@FindBy(className = "value test")
@CacheLookup
private WebElement test;
推荐答案
我不认为barak manos的答案已经完全解释
I don't think barak manos's answer has fully explained it.
想象一下我们有以下几个元素:
Imagine we have few elements as the followings:
-
< div class =value test>< / div>
-
< div class = value test>< / div>
-
< div class =first value test last> div>
-
< div class =test value>< / div>
/ li>
<div class="value test"></div>
<div class="value test "></div>
<div class="first value test last"></div>
<div class="test value"></div>
XPath如何匹配
-
仅匹配1(完全匹配),barak的回答
Match only 1 (exact match), barak's answer
driver.findElement(By.xpath("//div[@class='value test']"));
匹配1,2和3(匹配类包含
,类别顺序)
driver.findElement(By.xpath("//div[contains(@class, 'value test')]"));
匹配1,2,3和4(只要元素有< $ c> value 和 test
)
driver.findElement(By.xpath("//div[contains(@class, 'value') and contains(@class, 'test')]"));
-
匹配1
Match 1
driver.findElement(By.cssSelector("div[class='value test']"));
匹配1,2和3
Match 1, 2 and 3
driver.findElement(By.cssSelector("div[class*='value test']"));
匹配1,2,3和4
Match 1, 2, 3 and 4
driver.findElement(By.cssSelector("div.value.test"));
这篇关于通过多个类名来查找div元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文