![[Selenium]通过JavaScript来对隐藏的元素执行操作 [Selenium]通过JavaScript来对隐藏的元素执行操作](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
对不可见元素进行操作时,如果通过普通的方式不可行,可以尝试用Javascript
Scroll hidden element into view
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", widgetIconEl);
Click hidden element
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", element);
Get text of hidden element
String actualDataPointName = (String) ((JavascriptExecutor) driver).executeScript( "return jQuery(arguments[0]).text();", element);