【问题标题】:SeleniumGrid: org.openqa.selenium.WebDriverException: Unable to parse remote response: <html> <head> <title>SeleniumGrid:org.openqa.selenium.WebDriverException:无法解析远程响应:<html> <head> <title>
【发布时间】:2021-11-27 23:05:40
【问题描述】:

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

org.openqa.selenium.WebDriverException:无法解析远程响应:

但我不明白怎么回事

    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();   
    }
    

我该如何解决这个问题?

【问题讨论】:

  • 请匹配 chrome 和 chromedriver 版本并检查您的 url 是否正确。并添加屏幕截图和错误跟踪

标签: selenium selenium-webdriver selenium-grid remotewebdriver


【解决方案1】:

从您的驱动程序 URL 中删除 /wd/hub

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

【讨论】:

  • 我试过了。但随后它会给出另一个错误 - “org.openqa.selenium.remote.UnreachableBrowserException:无法启动新会话。可能的原因是远程服务器的地址无效或浏览器启动失败。构建信息:版本:'3.141。 59',修订:'e82be7d358',时间:'2018-11-14T08:17:03' 系统信息:主机:'DESKTOP-DGNP064',ip:'10.0.0.149',os.name:'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '16' 驱动信息: driver.version: RemoteWebDriver "
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-27
  • 2019-11-27
  • 1970-01-01
  • 2018-06-19
相关资源
最近更新 更多