2017-07-14 74 views
0

运行试图运行我的其他系统可执行的JAR文件时找不到元素,URL打开,打印标题,但无法找到的元素。给出以下错误。我无法理解我出错的地方。需要大家的帮助。谢谢。从其他终端

C:\Users\temp.BWT05574003\Documents\Sel Test Result>java -jar UserAccess_V02.jar 
Enter User EIN of System ==> BWT05574003 

611066167 - Login ID for T3 
Started InternetExplorerDriver server (32-bit) 
3.4.0.0 
Listening on port 29701 
Only local connections are allowed 
Jul 14, 2017 11:53:45 AM org.openqa.selenium.remote.ProtocolHandshake createSession 
INFO: Detected dialect: OSS 
Page Title -- 21C Authentication: Login 
Exception in thread "main" java.lang.reflect.InvocationTargetException 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58) 
Caused by: org.openqa.selenium.NoSuchElementException: Unable to find element with name == USER (WARNING: The server did not provide any stacktrace information) 

Command duration or timeout: 30.04 seconds 
For documentation on this error, please visit: http://seleniumhq.org/exceptions/ 
no_such_element.html 
Build info: version: 'unknown', revision: 'unknown', time: 'unknown' 
System info: host: 'BWT05574003', ip: '10.52.132.19', os.name: 'Windows Server 2008 R2', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_111' 
Driver info: org.openqa.selenium.ie.InternetExplorerDriver 
Capabilities [{se:ieOptions={browserAttachTimeout=0.0,ie.enableFullPageScreenshot=true, enablePersistentHover=true, ie.forceCreateProcessApi=false, ie.forceShellWindowsApi=false, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000.0, ie.useLegacyFileUploadDialogHandling=false, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0.0, ie.browserCommandLineSwitches=, requireWindowFocus=false, initialBrowserUrl=http://localhost:29701/, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true}, browserName=internet explorer, pageLoadStrategy=normal, javascriptEnabled=true, version=11, platform=WINDOWS, unexpectedAlertBehaviour=dismiss}] 
Session ID: 5d86998b-5b43-49f8-884f-e4a21c457a5d 
*** Element info: {Using=name, value=USER} 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 

    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 

    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
    at java.lang.reflect.Constructor.newInstance(Unknown Source) 
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215) 
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167) 
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:671) 
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:410) 
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByName(RemoteWebDriver.java:485) 
    at org.openqa.selenium.By$ByName.findElement(By.java:303) 
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:402) 
    at UserAccess.main(UserAccess.java:95) 
    ... 5 more 

我的代码

public static void main(String args[]) throws BiffException, IOException{ 

sc = new Scanner(System.in); 
System.out.print("Enter User EIN of System ==> "); 
EIN = sc.next(); 
System.out.println(); 

FilePath = "C:\\Users\\" + EIN + "\\Documents\\Sel Test Result\\UserAccess.xls"; 
fs = new FileInputStream(FilePath); 
wb = Workbook.getWorkbook(fs); 
sh = wb.getSheet("Sheet1"); 

int totalNoOfRows = sh.getRows(); 
EIN1 = readExcel(1,0); 
Pwd = readExcel(1,1); 

System.out.println(EIN1+" - Login ID for T3"); 

try 
{ 
    Runtime.getRuntime().exec("taskkill /F /IM IEDriverServer.exe"); 
} 
catch (IOException e) 
{ 
    e.printStackTrace(); 
} 

System.setProperty("webdriver.ie.driver", "C:\\Users\\" + EIN + "\\Documents\\Sel Test Result\\IEDriverServer\\IEDriverServer.exe"); 
driver = new InternetExplorerDriver(); 
driver.manage().window().maximize(); 
baseUrl = "http://bwt05574004.itsm.nat.bt.com:8080/arsys/home"; 

//baseUrl = "http://itsm.nat.bt.com:8080/arsys"; 

projectPath = "C:\\Users\\" + EIN + "\\Documents\\Sel Test Result"; 

driver.navigate().to(baseUrl); 
driver.manage().timeouts().implicitlyWait(30L, TimeUnit.SECONDS); 

System.out.println("Page Title -- " + driver.getTitle()); // Till Here Working 

WaitFor(5000); 

WebElement myElement = driver.findElement(By.name("USER")); 
myElement.sendKeys(new CharSequence[] { EIN1 }); 
WebElement myElement1 = driver.findElement(By.name("PASSWORD")); 
myElement1.sendKeys(new CharSequence[] { Pwd });code here 

HTML代码

<table width="100%" cellspacing="0" cellpadding="5"> 
 
    <tbody> 
 
    <tr> 
 
     <th>21C Authentication: Login</th> 
 
    </tr> 
 
    <script> 
 
     errorMsg("true"); 
 
    </script> 
 
    <tr> 
 
     <td align="center"> 
 
    </tr> 
 
    <tr> 
 
     <td align="left"> 
 
     <form class="form" autocomplete="off" method="post" name="Login"> 
 
      <span class="label"> 
 
      <br> 
 
      <input name="USER" maxlength="70" tabindex="1" accesskey="U"> 
 
      <br> 
 
      <span class="label"> 
 
      <u>P</u> 
 
      assword: 
 
      </span> 
 
      <br> 
 
      <input type="password" name="PASSWORD" maxlength="70" tabindex="2" accesskey="P"> 
 
      <a href="javascript:openPopUpWindow('http://passwords.intra.bt.com/ewebpass/input_form.cfm?preprocessed=SITEMINDER',670,530,true)" tabindex="5" title="Reset your password with eWebPass">Forgotten your password?</a>

+0

你的问题意味着这个相同的代码在你的系统上工作,这是正确的吗? –

+0

是......完美 –

+0

你能交叉检查一次,如果'By.name( “USER”)'和'By.name( “密码”)'对应的HTML DOM独特WebElements?谢谢 – DebanjanB

回答

0

,而不是硬编码5秒等待,请尝试使用WebDriverWait:

WebDriverWait wait = new WebDriverWait(driver,20); 
WebElement userField = wait.until(ExpectedConditions.elementToBeClickable(By.name("USER"))); 

这是完全有可能的是,页面加载在不同的机器慢。

+0

谢谢,但已经尝试过。 –

+0

请在你的问题中与我们分享你试过的其他东西,这样我们就不用花费更多的精力告诉你同样的事情。 –

+0

不便之处 –