[英]How to click Onclick from <a without text Javascript form using Selenium?
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). 我需要点击图片(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.
我将Selenium与chromewebdriver一起使用,我查看了选择OK,但是“ a” HTML栏杆中的onclick未检测到点击。
I see this: How to click Onclick Javascript form using Selenium? 我看到了: 如何使用Selenium单击Onclick Javascript表单? The solution is click to the text
<a ...> text </a>
but in my case I do not have any text. 解决方案是单击文本
<a ...> text </a>
但是在我的情况下,我没有任何文本。
I find a solution by javascript execution (from java): 我找到了通过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();");
In this example the xpath is the normal xpath.
在此示例中,xpath是普通的xpath。 The important element is executeScript (in java) and document.evaluate (in javascript).
重要元素是executeScript (在Java中)和document.evaluate (在javascript中)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.