unhandled inspector error: {"code":-32000,"message":"Cannot navigate to invalid URL"}这个错误的意思是:“未经处理的检查员错误:{“代码”:32000,“消息”:“无法定位到URL无效”}”
全部代码如下:
package cn.gloryroad;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
public class TestDemo2 {
WebDriver driver;
String baseUrl;
JavascriptExecutor js;
@Test
public void testDataPicker() throws Exception {
driver.get("baseUrl");
WebElement textInputBox = driver.findElement(By.id("text"));
setAttribute(driver,textInputBox,"value","文本框的文字和长度已经被修改了!");
setAttribute(driver,textInputBox,"size","10");
removeAttribute(driver,textInputBox,"size");
}
public void setAttribute(WebDriver driver,WebElement element,String attributeName,String value) {
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].setAttribute(arguments[1],arguments[2]", element,attributeName,value);
}
public void removeAttribute(WebDriver driver,WebElement element,String attributeName) {
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].removeAttribute(arguments[1],arguments[2]", element,attributeName);
}
@BeforeMethod
public void beforeMethod() {
baseUrl="http://localhost:8080/web/TestDataPicker.html";
System.setProperty("webdriver.chrome.driver", "driver/chromedriver.exe");
driver = new ChromeDriver();
}
@AfterMethod
public void afterMethod() {
driver.quit();
}
}
把driver.get("baseUrl");放到beforemethod方法中就解决了