[Selenium]通过JavaScript来对隐藏的元素执行操作

时间:2023-03-09 03:29:36
[Selenium]通过JavaScript来对隐藏的元素执行操作

对不可见元素进行操作时,如果通过普通的方式不可行,可以尝试用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);