public class CJavaScriptExecutor {
public static WebDriver driver;
private static JavascriptExecutor js= (JavascriptExecutor)driver;
public static void highLighElement(WebElement element){
js.executeScript("arguments[0].setAttribute('style', 'background:
yellow; border: 2px solid red;');", element);
}
当我在另一个类中调用Highlight方法的代码如下时,它将引发空指针异常。
WebElement frame =driver.findElement(By.id("productPillarFrame"));
CJavaScriptExecutor.highLighElement(frame);