簡體   English   中英

org.openqa.selenium.remote.UnreachableBrowserException與遠程瀏覽器幻象js通信時出錯

[英]org.openqa.selenium.remote.UnreachableBrowserException Error communicating with the remote browser phantom js

我正在嘗試使用硒自動化gmail發送電子郵件,我正在使用幻影js(無頭)

我收到以下異常

org.openqa.selenium.remote.UnreachableBrowserException與遠程瀏覽器通信時出錯

Capabilities caps = new DesiredCapabilities();
         ((DesiredCapabilities) caps).setJavascriptEnabled(true);                
         ((DesiredCapabilities) caps).setCapability("takesScreenshot", true);
         ((DesiredCapabilities) caps).setCapability(
                 PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
                 "C:\\jars\\phantomjs-2.0.0-windows\\bin\\phantomjs.exe"
             );
        //File file = new File("C:/jars/phantomjs-2.0.0-windows/bin/phantomjs.exe");             
       // System.setProperty("phantomjs.binary.path", file.getAbsolutePath());        
       WebDriver d = new PhantomJSDriver(caps); 

//WebDriver d=new HtmlUnitDriver();
        WebDriverWait wait = new WebDriverWait(d, 10);
        d.get("https://www.gmail.com/intl/en/mail/help/about.html");
        System.out.println("navigated to gmail");
        d.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        d.manage().window().setSize(new Dimension(1576, 798));;

        d.findElement(By.id("gmail-sign-in")).click();
        System.out.println("Clicked on Signin");
        Thread.sleep(9000);


        d.findElement(By.id("Email")).sendKeys("chaitanyapujari97@gmail.com");
        System.out.println("Entered Email");

        Thread.sleep(9000);
        d.findElement(By.id("next")).click();


        System.out.println("Clicked next");
        d.findElement(By.id("Passwd")).sendKeys("your pwd");
        System.out.println("Entered password");
        Thread.sleep(9000);
        d.findElement(By.id("signIn")).click();
        System.out.println("Clicked on signin");
        Thread.sleep(9000);


        d.findElement(By.xpath("html/body/div[7]/div[3]/div/div[2]/div[1]/div[1]/div[1]/div[2]/div/div/div[1]/div/div")).click();
        System.out.println("Clicked on Compose email");
        //Thread.sleep(9000);
        Thread.sleep(9000);


        d.findElement(By.name("to")).sendKeys("your email");
        System.out.println("Entered To address");

        Thread.sleep(9000);
        d.findElement(By.name("q")).click();
        d.findElement(By.name("subjectbox")).sendKeys("PHANTOm Js");

        System.out.println("Entered Subject");
        //WebElement webElement=d.findElement(By.name("subjectbox"));

        /*String keysPressed =  Keys.chord(Keys.CONTROL, Keys.RETURN);
         WebElement element=d.findElement(By.xpath("html/body"));
         element.sendKeys(keysPressed) ;*/
         Thread.sleep(9000);
         d.findElement(By.xpath("html/body/div[14]/div/div/div/div[1]/div[3]/div[1]/div[1]/div/div/div/div[3]/div/div/div[4]/table/tbody/tr/td[2]/table/tbody/tr[2]/td/div/div/div[4]/table/tbody/tr/td[1]/div/div[2]")).click();
        System.out.println("Clicked On send"); 

我能夠添加收件人電子郵件地址,並且主題無法單擊“發送”按鈕。

我無法弄清楚我是無頭硒自動化的新手,請幫助,

請嘗試此操作,希望對您有所幫助,為什么要使用這么長的XPATH,它必須從html遍歷。

 d.findElement(By.xpath(".//tr[@class='n1tfz']/td[1]/div[1]/div[2]")).click();

我發現問題出在我正在使用jar phantomjsdriver-1.1.0.jar的jar中,現在我已經更改了jar的版本,即phantomjsdriver-1.2.1.jar可以很好地工作。

感謝您的幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM