[英]Trigger native click() and not Selenium click() on an element
I am writing a test case and accessing a Selenium WebElement as follows -我正在编写一个测试用例并访问 Selenium WebElement,如下所示 -
WebElement printButton = driver.findElement(By.xpath("//*[text()='Print']"));
Now I want to perform a click on the above element but I don't want to use selenium's click().现在我想点击上面的元素,但我不想使用 selenium 的 click()。 I want to use a lower level Javascript or JQuery's click().
我想使用较低级别的 Javascript 或 JQuery 的 click()。
For this I converted the WebElement into a String that contains the element in its HTML form -为此,我将 WebElement 转换为包含其 HTML 形式的元素的字符串 -
String s = printButton.getAttribute("outerHTML");
The value stored in this String is "<span>Print<span>"
.此字符串中存储的值是
"<span>Print<span>"
。
Now I am stuck.现在我被困住了。 I am aware that there is a Selenium function
driver.executeScript();
我知道有一个 Selenium function
driver.executeScript();
but Im not sure how to do it.但我不知道该怎么做。
Please help!请帮忙!
Simple as that:)就那么简单:)
WebElement printButton = driver.findElement(By.xpath("//*[text()='Print']"));
driver.executeScript("arguments[0].click()", printButton);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.