使用selenium webdriver在Firefox中自动运行web应用程序时发生检查异常 import org.openqa.selenium.*; 导入org.openqa.selenium.firefox.FirefoxDriver; 公共类shopComLogin{ 公共静态void main(字符串[]args)引发InterruptedException{ //启动Firefox浏览器 WebDriver窗口=新的FirefoxDriver(); //导航至Shop.com 试一试{ 窗口。获取(“http://www.shop.com/"); 睡眠(4000); findelelement((By.xpath(“./*[@id='global-redirects']/div[2]/a[1]/div[1]/div[1]”)。单击(); 《睡眠》(2000年); WebElement wb=window.findElement(By.xpath(“./*[@id='super-header-menu']]/div[1]/a”); wb.click(); 睡眠(4000); 字符串enteredEmailId=”shantanunandann@gmail.com"; findElement(By.xpath(“.//*[@id='sign\u in\u email\u textfield']”); window.findElement(By.xpath(“./*[@id='no\u account\u单选按钮'])。单击(); window.findElement(By.xpath(“./*[@id='signin_button']”)。单击(); 《睡眠》(2000年); String actualmailid=window.findElement(By.xpath(“./*[@id='sign\u in\u email\u textfield']”); if(输入邮件ID.equalsIgnoreCase(实际邮件ID)){ System.out.println(“相同的电子邮件id”+实际邮件id); }//如果关闭 否则{ System.out.println(“电子邮件id字段值不匹配”); window.close(); }//否则关闭 }//接近 捕捉(中断异常中断){ interrupt.printStackTrace(); }//紧扣 }//主关闭 }//停课 我得到的这个程序的例外是- 线程“main”org.openqa.selenium.WebDriverException中出现异常:无法在45000毫秒内绑定到锁定端口7054 构建信息:版本:“2.39.0”,修订版:“ff23eac”,时间:“2013-12-16 16:12:12” 系统信息:主机:'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.version:FirefoxDriver 位于org.openqa.selenium.internal.SocketLock.lock(SocketLock.java:98) 位于org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:84) 位于org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:250) 位于org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:110) 位于org.openqa.selenium.firefox.FirefoxDriver(FirefoxDriver.java:197) 位于org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:190) 位于org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:186) 位于org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:99) 位于shopComLogin.main(shopComLogin.java:7)

使用selenium webdriver在Firefox中自动运行web应用程序时发生检查异常 import org.openqa.selenium.*; 导入org.openqa.selenium.firefox.FirefoxDriver; 公共类shopComLogin{ 公共静态void main(字符串[]args)引发InterruptedException{ //启动Firefox浏览器 WebDriver窗口=新的FirefoxDriver(); //导航至Shop.com 试一试{ 窗口。获取(“http://www.shop.com/"); 睡眠(4000); findelelement((By.xpath(“./*[@id='global-redirects']/div[2]/a[1]/div[1]/div[1]”)。单击(); 《睡眠》(2000年); WebElement wb=window.findElement(By.xpath(“./*[@id='super-header-menu']]/div[1]/a”); wb.click(); 睡眠(4000); 字符串enteredEmailId=”shantanunandann@gmail.com"; findElement(By.xpath(“.//*[@id='sign\u in\u email\u textfield']”); window.findElement(By.xpath(“./*[@id='no\u account\u单选按钮'])。单击(); window.findElement(By.xpath(“./*[@id='signin_button']”)。单击(); 《睡眠》(2000年); String actualmailid=window.findElement(By.xpath(“./*[@id='sign\u in\u email\u textfield']”); if(输入邮件ID.equalsIgnoreCase(实际邮件ID)){ System.out.println(“相同的电子邮件id”+实际邮件id); }//如果关闭 否则{ System.out.println(“电子邮件id字段值不匹配”); window.close(); }//否则关闭 }//接近 捕捉(中断异常中断){ interrupt.printStackTrace(); }//紧扣 }//主关闭 }//停课 我得到的这个程序的例外是- 线程“main”org.openqa.selenium.WebDriverException中出现异常:无法在45000毫秒内绑定到锁定端口7054 构建信息:版本:“2.39.0”,修订版:“ff23eac”,时间:“2013-12-16 16:12:12” 系统信息:主机:'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.version:FirefoxDriver 位于org.openqa.selenium.internal.SocketLock.lock(SocketLock.java:98) 位于org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:84) 位于org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:250) 位于org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:110) 位于org.openqa.selenium.firefox.FirefoxDriver(FirefoxDriver.java:197) 位于org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:190) 位于org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:186) 位于org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:99) 位于shopComLogin.main(shopComLogin.java:7),java,firefox,exception,selenium,selenium-webdriver,Java,Firefox,Exception,Selenium,Selenium Webdriver,我今天运行这个程序。对于前2次执行,我得到了所需的输出,不包括if块。在第4次运行时,程序开始给出上面代码中提到的异常。不知道我为什么会得到这个以及如何修复它 其次,在我的前2次执行中,if块中编写的代码根本没有执行,即,我没有得到所需的输出,也没有任何异常或错误。谁能告诉我为什么 我在下面读了一些对我有用的东西 这是因为不止一个javaw.exe在后台运行。杀死这些进程并尝试一下 Hi Shantanu,出现异常的原因之一可能是在第二次执行脚本之前,firefox进程可能没有关闭。对于第二个问

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


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

我在下面读了一些对我有用的东西

这是因为不止一个javaw.exe在后台运行。杀死这些进程并尝试一下


Hi Shantanu,出现异常的原因之一可能是在第二次执行脚本之前,firefox进程可能没有关闭。对于第二个问题,请拆下。在xpath中。希望这能解决问题。编码快乐。@vijay嗨vijay,你在firefox运行的背景中是对的。我在任务管理器中杀死了它,现在它工作了。但是对于第二个问题,我没有得到ActualMailId的任何字符串值。你知道吗?我的名字是Vinay:)你能分享电子邮件id的html吗。会让你知道它没有被识别的原因。@Vinay很抱歉Vinay输入了错误的名字(Vijay是我的朋友,这就是你为什么犯了那个愚蠢的错误)。如何发送电子邮件ID的html?你说的是我试图获取数据的网页吗?该页面的链接在if块中,而不是getText()使用getAttribute(“value”)。如果您想从editBox中获取文本,那么您应该使用这个而不是getText。我还看到所有字段都有ID。使用ID而不是xpath。仅为动态场景保留xpath。
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)