2017-03-29 99 views
2

我想点击使用div标签的style属性在网页上显示的按钮。如何在java selenium的样式属性的基础上点击

但我无法这样做。我引用了堆栈溢出,但借助于它返回的空白元素。我不想要任何文字。我希望它应该被点击并且列表出现,我想从列表中选择一个项目。那么该怎么做?

下面是我的代码:

<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;"); 

我在这里严重卡住了。提前感谢!

回答

3

试试以下代码。

如果你想点击<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的说明: - 使用class<div>标签的style属性。

+1

谢谢@ jainish,但它点击我不想要的图像。我想点击图像下方的其他div。我编辑你的代码,但它不起作用driver.findElement( \t \t \t \t .xpath(“// div [@ class ='Qv_HotSpot']/div [@ style ='cursor:pointer; position:absolute; top:4px; left:588px; height:18px; width:27px']“)) \t \t \t \t .click(); –

+0

我已经更新了我的答案,请检查它。 –

+0

现在是你想要的吗?你能解释我为什么要修改我的'xpath'吗?请用您的代码替换我的代码。然后只有它为你工作。 –