Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法使用Selenium单击元素。单击()_Javascript_Jquery_Selenium_Selenium Webdriver - Fatal编程技术网

Javascript 无法使用Selenium单击元素。单击()

Javascript 无法使用Selenium单击元素。单击(),javascript,jquery,selenium,selenium-webdriver,Javascript,Jquery,Selenium,Selenium Webdriver,下面是HTML标记: <div onscroll="return isc_Canvas_4.$lh()" style="position: absolute; left: 6px; top: 6px; width: 12px; height: 12px; z-index: 201854; overflow: hidden; -moz-box-sizing: border-box; cursor: pointer; margin: 0px; padding: 0px; border: 0px

下面是HTML标记:

<div onscroll="return isc_Canvas_4.$lh()" style="position: absolute; left: 6px; top: 6px; width: 12px; height: 12px; z-index: 201854; overflow: hidden; -moz-box-sizing: border-box; cursor: pointer; margin: 0px; padding: 0px; border: 0px none; display: inline-block;" class="fa fa-caret-down" eventproxy="isc_Canvas_4" id="isc_55">&nbsp;</div>

我想使用Selenium单击此元素。我尝试过selenium element.click(),但它不起作用


有人能提出其他建议吗?可以通过Selenium中的JS或JQuery来实现。

在元素上执行javascript的地方尝试一下以下内容:

JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", element);

我想试试这样的东西

如果DIV的ID在每次加载时都相同:

driver.findElement(By.id("isc_55")).click();
否则,如果DIV的文本是唯一存在的文本:

driver.findElement(By.xpath("//div[contains(text(), '&nbsp;')]")).click();
甚至可能:

driver.findElement(By.xpath("//div[text()='&nbsp;']")).click();

更多的html和一些代码会有很大帮助吗?

你能解释一下你是如何定义你想点击的
元素的吗?此外,我认为您应该提供更多的HTML代码片段,而不是上述内容。如果您提供了这些,我们将能够帮助您使用xpath.xpath来定位元素,这里什么都不起作用。我能够找到元素并检索其属性,但无法在@TDHM处单击它。我认为JS或JQuery可以在这里提供帮助,因为div通常不能点击。这很可能就是问题所在。当你点击该
div
时会发生什么?据我所知,在我得到该元素的网页之前,我将无法帮助你,而且我也不知道点击带有
div
标记的元素后会发生什么。显然,元素既不表示按钮也不表示链接。如何在Selenium中使用JQuery单击元素?对不起,我不知道JQuery。