SeleniumGrid: org.openqa.selenium.WebDriverException: 无法解析远程响应: <html> <head> <title&



我正在尝试使用selenium编写测试用例。我写了这段代码。我得到了这个错误

org.openqa.selenium。WebDriverException: cannot parse remote response:

但我不明白是怎么回事

public static WebDriver driver=null;
ATUTestRecorder recorder;

@Parameters({"browsername"})
@BeforeTest
public void setUpBrowser(String browsername) throws ATUTestRecorderException, MalformedURLException
{
String timeStamp = new SimpleDateFormat("yy-MM-dd_HH-mm-ss").format(new Date());
recorder = new ATUTestRecorder("./ScreenRecorder/","Test_"+timeStamp+".mp4",false);
DesiredCapabilities cap =null;
if(driver==null)
{
if(browsername.equalsIgnoreCase("Firefox"))
{
// Set the path for geckodriver.exe
//System.setProperty("webdriver.gecko.driver", "./Drivers/geckodriver.exe");
//WebDriverManager.firefoxdriver().setup();
cap = DesiredCapabilities.firefox();
cap.setBrowserName("firefox");
cap.setPlatform(Platform.ANY);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),cap);
}           
// If the browser is Chrome
else if(browsername.equalsIgnoreCase("Chrome"))
{
// Set the path for chromedriver.exe
System.setProperty("webdriver.chrome.driver", "./Drivers/chromedriver.exe");
//WebDriverManager.chromedriver().setup();
cap = DesiredCapabilities.chrome();
cap.setBrowserName("chrome");
cap.setPlatform(Platform.ANY);
System.out.println(driver);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),cap);
}
// If the browser is IE
else if(browsername.equalsIgnoreCase("IE"))
{
// Set the path for IEdriver.exe
//System.setProperty("webdriver.ie.driver", "./Drivers/IEDriverServer.exe");
//WebDriverManager.iedriver().setup();
cap = DesiredCapabilities.internetExplorer();
cap.setBrowserName("internetExplorer");
cap.setPlatform(Platform.ANY);

driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),cap);
}

driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get(DataConfig.baseURL);
}
recorder.start();   
}

如何解决这个问题?

从驱动URL中删除/wd/hub

参见示例https://www.selenium.dev/documentation/webdriver/remote_webdriver/

你的Selenium URL应该是:

http://localhost: 4444/wd/中心

也请更新Webdrivermanager依赖到最新的,我用5.4.0它工作。

最新更新