Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.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 Solve$(…)[0]是未定义的错误_Javascript_Java_Html_Selenium_Scroll - Fatal编程技术网

Javascript Solve$(…)[0]是未定义的错误

Javascript Solve$(…)[0]是未定义的错误,javascript,java,html,selenium,scroll,Javascript,Java,Html,Selenium,Scroll,我试图通过使用原生scrollHeight属性返回DOM元素本身来获取div框的滚动高度 Long scrollHeight = (Long) jse.executeScript("return $(\"//*[@id='react-root']/section/main/div/div/article/div[2]/ul\")[0].scrollHeight"); 但是,我遇到了以下错误:org.openqa.selenium.WebDriverException:$(…)[0]未定义。我怎

我试图通过使用原生scrollHeight属性返回DOM元素本身来获取div框的滚动高度

Long scrollHeight = (Long) jse.executeScript("return $(\"//*[@id='react-root']/section/main/div/div/article/div[2]/ul\")[0].scrollHeight");
但是,我遇到了以下错误:org.openqa.selenium.WebDriverException:$(…)[0]未定义。我怎样才能着手解决这个问题

网页如


我不想使用div框的类名,因为这只是我想从中获取滚动高度的网站之一。类名将不同于各种网页。

将xpath选择器转换为css选择器:

Long scrollHeight=(Long)jse.executeScript(“return$('#react root ul')[0].scrollHeight”);

发生这种情况是因为您的选择器没有带来任何东西,您想用此选择器选择哪个元素?@RodrigoLeite我想用此选择器选择一个div框或您可以共享网页链接吗?@drets请查看编辑此错误出现在org.openqa.selenium.WebDriverException:$x在为浏览器添加导入后未定义,不兼容的类型会出现此错误:int无法转换为JavaScriptExecutor使用您的代码实现-仅更改
executeScript
方法的参数