使用selenium webdriver在Firefox中自动化Web应用程序时获取检查异常

时间:2014-05-22 07:06:54

标签: java firefox exception selenium selenium-webdriver

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;

public class shopComLogin {
   public static void main(String[] args) throws InterruptedException{
   //Launch a Firefox Browser
   WebDriver window=new FirefoxDriver();
   //Navigating to Shop.com
   try{
   window.get("http://www.shop.com/");
   Thread.sleep(4000);
   window.findElement((By.xpath(".//*[@id='global-redirects']/div[2]/a[1]/div[1]/div[1]"))).click();
   Thread.sleep(2000);
   WebElement wb=window.findElement(By.xpath(".//*[@id='super-header-menu']/div[1]/a"));
   wb.click();
   Thread.sleep(4000);
   String enteredEmailId="shantanunandann@gmail.com";
   window.findElement(By.xpath(".//*[@id='sign_in_email_textfield']")).sendKeys(enteredEmailId);
   window.findElement(By.xpath(".//*[@id='no_account_radio_button']")).click();
   window.findElement(By.xpath(".//*[@id='signin_button']")).click();
   Thread.sleep(2000);
   String actualEmailId=window.findElement(By.xpath(".//*[@id='sign_in_email_textfield']")).getText();
   if(enteredEmailId.equalsIgnoreCase(actualEmailId)){
       System.out.println("Same email id "+ actualEmailId);
      }//if closed
      else{
     System.out.println("Email id field value does't match");  
     window.close();
   }//else closed
  }//try close
   catch(InterruptedException interrupt){
       interrupt.printStackTrace();
  }//catch close
 }//main closed
}//class closed

Exception which i am getting for this program is-
 Exception in thread "main" org.openqa.selenium.WebDriverException: Unable to bind to locking port 7054 within 45000 ms
 Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: 'omega-d52b83806', ip: '10.0.0.7', os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0_45'
  Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.internal.SocketLock.lock(SocketLock.java:98)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:84)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:250)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:197)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:190)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:99)
at shopComLogin.main(shopComLogin.java:7)

我今天运行这个程序。对于前两次执行,我得到了所需的输出,不包括if块。在第4次运行时,程序开始给我异常,如上面的代码中所述。不知道为什么我会得到这个以及如何解决它。

其次,在我的前两次执行中,if块内部写的代码根本没有执行,即我没有获得所需的输出,也没有任何异常或错误。谁能告诉我为什么?

1 个答案:

答案 0 :(得分:0)

我读了一些&amp;它对我有用。

它因为多个javaw.exe在后台运行。杀死这些流程并试一试。

https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/taskman_end_process.mspx?mfr=true