线程“main”中的异常org.openqa.selenium.remote.UnreachableBrowserException:

时间:2016-05-10 08:47:39

标签: java selenium selenium-chromedriver

当我尝试运行我的selenium项目时,我收到错误以下错误。

以下是代码:

package automationFramework;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import java.util.concurrent.TimeUnit;

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.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
//import org.openqa.selenium.support.ui.Select;

public class FirstTestCase {

//private static final String JavascriptExecutor = null;


public static void main(String[] args) throws InterruptedException, AWTException {

WebDriver driver = new ChromeDriver();

        //Launch the Test A Environment
        driver.get("https://ivv-a.entityhub.clarientglobal.dev");


        driver.manage().window().maximize();

        //Thread.sleep(3000);        
        driver.findElement(By.cssSelector("#username")).sendKeys("user3@imb.com");
        //Thread.sleep(1000);
        driver.findElement(By.cssSelector("#password")).sendKeys("Cred123#");
        //Thread.sleep(1000);
        driver.findElement(By.cssSelector("#submit")).click();
        //Thread.sleep(1000);


        //Wait for 15 Sec for the page to load
        Thread.sleep(15000);

        /*Actions action = new Actions(driver);
        WebElement el = driver.findElement(By.xpath("/html/body/div[1]/div[1]/nav/div[2]/section/aside/ul/li[2]/a"));
        action.moveToElement(el).build().perform();
        Actions builder = new Actions(driver);
        builder.moveToElement(driver.findElement(By.cssSelector("body > div.sticky__body > div.credHeader.ng-scope > nav > div.header__nav--primary.ng-scope > section > aside > ul > li:nth-child(2) > ul > li:nth-child(3) > a"))).click().build().perform(); */

        WebElement entityrecordsmenu = driver.findElement(By.cssSelector("body > div.sticky__body > div.credHeader.ng-scope > nav > div.header__nav--primary.ng-scope > section > aside > ul > li:nth-child(2) > a"));
        Actions builder = new Actions(driver);
        builder.moveToElement(entityrecordsmenu).build().perform();

        //provide wait here to display drop-down
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        //some time implicitly wait may fails then use thread.sleep
        Thread.sleep(6000);
        WebElement createnewrecord = driver.findElement(By.cssSelector("body > div.sticky__body > div.credHeader.ng-scope > nav > div.header__nav--primary.ng-scope > section > aside > ul > li:nth-child(2) > ul > li:nth-child(2) > a"));
        createnewrecord.click();

        //By locator = By.id("elem2");
        //WebElement element = driver.findElement(By.cssSelector("body > div.sticky__body > div.credHeader.ng-scope > nav > div.header__nav--primary.ng-scope > section > aside > ul > li.ng-isolate-scope.selected > ul > li:nth-child(3) > a"));
        //element.click(); 

        //Mouse hover and drop down clicked

        Thread.sleep(13000);



        driver.findElement(By.xpath("//*[@id='search-results']/div[2]/table/tbody/tr[1]/td[1]/a")).click();
        Thread.sleep(7000);
        //driver.findElement(By.cssSelector("#legalName")).sendKeys("IMB");

        ((JavascriptExecutor)driver).executeScript("scroll(0,400)");

        Thread.sleep(5000);

        Thread.sleep(2000);

        WebElement SaveDraftbutton = driver.findElement(By.cssSelector("#submitBtn > span:nth-child(2)"));
        SaveDraftbutton.click();

        Thread.sleep(6000);

        ((JavascriptExecutor)driver).executeScript("scroll(0,900)");

        Thread.sleep(6000);


        Robot robot = new Robot();

        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_V);
        robot.keyRelease(KeyEvent.VK_V);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);

        //driver.findElement(By.cssSelector("#collapseDocuments > div > div > div > div > div:nth-child(3) > div > div > div.controls.control-group > div.col-md-2.add-doc-button.button.ng-isolate-scope")).sendKeys("C:\\Users\\siva.247588\\Desktop\\Clarient+AML+Questionnaire.docx");

    }

}

我添加了部分代码。这工作得很好。遗憾的是,我对jar文件的路径进行了一些更改,之后显示了以下错误消息。

Exception in thread main"org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
    Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
    System info: host: 'CHNMCT271738D', ip: '10.87.32.163', os.name: 'Windows 8.1', os.arch: 'x86', os.version: '6.3', java.version: '1.8.0_72'
    Driver info: driver.version: ChromeDriver"

有人可以建议解决方案吗?

2 个答案:

答案 0 :(得分:0)

我们不能像这样立即启动Chrome浏览器

  

WebDriver driver = new ChromeDriver();

首先从here

下载Chrome驱动程序

然后设置系统属性

System.setProperty("webdriver.chrome.driver", "/path to download chromedriver.exe");

WebDriver driver = new ChromeDriver();

然后将打开Chrome浏览器,没有任何问题。

答案 1 :(得分:0)

我尝试了命令WebDriver driver = new ChromeDriver(DesiredCapabilities.chrome());它没有任何问题就启动了Chrome浏览器..