This is my source code :
<a onclick="pd(event);" tabindex="0" issprite="true" data-ctl="Icon"
style="overflow: hidden; background: transparent
url("webwb/pygridicons_12892877635.png!!.png") no-repeat scroll 0px top; width:
16px; height: 16px;" name="ManageStakeholder_pyWorkPage_202"
title="Add a data " data-click="[["doGridAction",
[":event","INSERTAFTER"]],["refresh", ["thisSection","", "", "&=", "",
",",":event","","pyWorkPage"]]]" data-hover="[["changeStyle",
[":event","background-position:0px -16px;", "1"]]]"
onmouseover="pega.c.cbe.processBehavior(event, "data-hover")"></a>
I need click to image (pygridicons_12892877635.png). I using Selenium with chromewebdriver and I look at the selection OK but the onclick from "a" HTML balise do not detected the click.
I see this: How to click Onclick Javascript form using Selenium?点击Onclick解决方案是点击文字<a ...> text </a>
,但在我的情况下,我没有任何文字。
答案 0 :(得分:0)
我通过javascript执行找到了解决方案(来自java):
import org.openqa.selenium.JavascriptExecutor;
String xpath = "//table[@param_name='SubSectionManage~pzLayout_3']//a[@title='Add a data ']";
((JavascriptExecutor) webDriver).executeScript("document.evaluate(\"" + xpath + "\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();");
在此示例中,xpath是正常的xpath。重要的因素 是 executeScript (在java中)和 document.evaluate (在javascript中)。