如何单击具有动态变量的类

时间:2019-01-16 21:05:31

标签: java selenium web automation driver

我希望能够通过cluster-id-hash =“ foobar”进行搜索和单击,但是我也无法。它找不到元素

以下是页面上CSS的一些示例

<div class="ancCol w33 person-panel" _ngcontent-c6="" cluster-id-hash="KYDQEX8il7BIG2"></div>

or
<div class="ancCol w33 person-panel annColRow" _ngcontent-c6="" cluster-id-hash="5gamjajdkjgPcma">

我已经尝试过了,其中clusterIdHash是我传递的字符串:

driver.findElement(By.cssSelector(".cluster-id-hash='" + clusterIdHash )).click();

1 个答案:

答案 0 :(得分:2)

想通了

driver.findElement(By.cssSelector("[cluster-id-hash='" + clusterIDHash + "']")).click();