org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server

被刻印的时光 ゝ 提交于 2019-11-28 14:18:19

You have to consider a couple of factors in your code as follows:

  1. You have created an object of the same class through PractiseSession1 ade= new PractiseSession1(); and using the object ade to call the different methods OpenBrowser(), GetPage() and quitbrowser(). The functionality performed by the methods can be achieved through a single line of code within main() and that too without creating any object.
  2. While using Selenium 3.x following the W3C Standards, to work with geckodriver.exe we need to use webdriver.gecko.driver instead of webdriver.firefox.marionette in the System.setProperty line.
  3. While you mention System.setProperty you need to provide the absolute path of the geckodriver.exe as follows:

    System.setProperty("webdriver.gecko.driver", "C:\\your_directory\\geckodriver.exe");
    
  4. Once you mention ImplicitlyWait, it is retained throughout the execution of your program. You may consider removing the multiple mentions.

    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

  5. Your entire code can be written in just 6 lines as follows:

    package demo;
    
    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.remote.DesiredCapabilities;
    
    public class Q44308973_remote_unreachablebrowserexception {
    
    public static void main(String[] args) 
    {
    
    System.setProperty("webdriver.gecko.driver", "C:\\your_directory\\geckodriver.exe");
    DesiredCapabilities dc = DesiredCapabilities.firefox();
    dc.setCapability("marionette", true);
    WebDriver driver =  new FirefoxDriver(dc);
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.get("https://google.com");
    }
    
    }   
    

For a detailed understanding of how webdriver.firefox.marionette evolved to be webdriver.gecko.driver you can watch this space.

You should replace

driver = new FirefoxDriver();

with

driver = new FirefoxDriver(capabilities);

so that you run the test with the desired capabilities.

Only issue with that is that it may not work with 3.4.0 as the default timeout value was reduce and may be too short now.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!