修改元素的style,主要是将一些隐性元素显示出来,让元素可被操作:
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("document.getElementById(‘name‘).style.display=‘block‘;");
或
JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement element = driver.findElement(By.xxx);
js.executeScript("arguments[0].style=arguments[1]",element,"display: block;");
对于某些富文本或者一些特殊类型的input输入框,使用javascript给其赋值:
File file = new File("resources/text");
WebElement input =driver.findElement(By.id("xxxx");((JavascriptExecutor)driver).executeScript("arguments[0].value=arguments[1]",input, file.getAbsolutePath());
原文地址:https://www.cnblogs.com/yunman/p/8368419.html
时间: 2024-10-07 18:06:38