如何根据 java selenium 中的样式属性单击

How to click on the basis of style attribute in java selenium

我想使用 div 标签的 style 属性单击在网页上显示为按钮的元素。

但是我做不到。我提到了堆栈溢出,但在它返回空白元素的帮助下。我不要任何文字。我希望它应该被点击并出现列表,我想从该列表中 select 一个项目。那么该怎么做呢?

下面是我的代码:

<div style="width: auto; height: 386px;" class="QvGraph">
<img src=" " style="width: 710px; height: 386px; cursor: crosshair; visibility: visible; display: block;"></img>
<div style="cursor: pointer; position: absolute; top: 4px; left: 588px; height: 18px; width: 27px;" class="Qv_Hotspot"></div>
<div style="cursor: pointer; position: absolute; top: 3px; left: 3px; height: 18px; width: 18px;" class="Qv_Hotspot"></div></div>
</div>  

我试过下面的代码,但它对我不起作用。

driver.findElement(By.xpath("//div[@class ='Qv_HotSpot']")).getAttribute("cursor: pointer; position: absolute; top: 4px; left: 588px; height: 18px; width: 27px;");  

我被困在这里了。提前致谢!

试试下面的代码。

如果您想点击 <div> 标签 style 属性,请使用以下代码。

driver.findElement(By.xpath("//div[@class='Qv_Hotspot'][@style='cursor: pointer; position: absolute; top: 4px; left: 588px; height: 18px; width: 27px;']")).click();

xpath 说明:- 使用 <div> 标签的 classstyle 属性。