[英]Element not found when running from other terminal
Trying to run my executable jar on other system, URL opened, prints title but not able to find the element. 尝试在其他系统上运行我的可执行jar时,打开URL,打印标题,但找不到该元素。 Gives following error.
给出以下错误。 I am not able to understand where I am going wrong.
我无法理解我要去哪里。 Need help from you all.
需要大家的帮助。 Thanks.
谢谢。
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
My Code 我的密码
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 Code 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>
Rather than a hard coded 5 second wait, try using WebDriverWait: 与其使用5秒的硬编码等待,不如尝试使用WebDriverWait:
WebDriverWait wait = new WebDriverWait(driver,20);
WebElement userField = wait.until(ExpectedConditions.elementToBeClickable(By.name("USER")));
It's entirely possible that the page loads slower on different machines. 页面在不同计算机上加载的速度很可能很慢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.