testcase在chrome中失败了

时间:2014-12-15 11:49:09

标签: javascript google-chrome selenium

您好我正在尝试在Chrome浏览器中运行测试用例并且测试用例在Firefox中传递但是在Chrome浏览器中失败了 。这是硒代码<​​/ p>

_driver.findElement(By.linkText("Expence_Link")).click();;
_driver.findElement(By.id("searchButton")).click();
_driver.findElement(By.id("descriptionInput")).sendKeys("Description");
_driver.findElement(By.id("saveAndNextExpenseButton")).click();

这是html代码

<input id="searchButton" class="formSubmit" type="button" value="Search" tabindex="3">
<a href="https://xyz/Collaborate?pbId=77501&sB=yat93&op=AddProjectBudgetActualExpense">Expence_Link</a>
<input id="descriptionInput" name="pre.projectBudgetActualExpense.description.value" value="" size="30" style="width:300px" tabindex="4" maxlength="665">
<input id="saveAndNextExpenseButton" class="formSubmit" type="button" onclick="onSaveAndNextExpenseButtonClick(); return false;" value="Save & Next Actual" tabindex="13">

,它显示的错误是

org.openqa.selenium.NoSuchElementException: no such element
(Session info: chrome=39.0.2171.95)
 (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64) (WARNING:     The server did not provide any stacktrace information)
Command duration or timeout: 3.02 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions     /no_such_element.html
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:17:32'
System info: host: 'ADMINIB-BHMHBF7', ip: '9.109.111.10', os.name: 'Windows 7',     os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_25'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, chrome=       {userDataDir=C:\Users\IBM_AD~1\AppData\Local\Temp\scoped_dir4692_20611},     takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=39.0.2171.95,    platform=XP, browserConnectionEnabled=false, nativeEvents=true,     acceptSslCerts=true, locationContextEnabled=true,     webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true,     cssSelectorsEnabled=true}]
Session ID: 03b44e91e408e56380c5d261b07cc97f
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:193)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:348)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:445)
at org.openqa.selenium.By$ByXPath.findElement(By.java:357)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:340)
at uiactions.Wrappers.SendKeys(Wrappers.java:254)
at test.object.ExpencePage_Object.Description_Fn(ExpencePage_Object.java:43)
at test.function.ExpencePage_Function.Expence_Page_Test(ExpencePage_Function.java:41)
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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

我无法将密钥发送到带有id&#39; descriptionInput&#39;的文本框中我尝试了名称,xpath,cssSelector,但没有任何工作。点击费用链接和搜索按钮在chrome中工作正常

请帮我解决这个问题 提前谢谢

1 个答案:

答案 0 :(得分:0)

尝试使用下面的Explicit wait等待字段的可见性,然后向其发送值:

//Waiting for 10 seconds for the presence of the description field and then entering text 'Description'
try{
    WebElement input_desc = new WebDriverWait(_driver,10).until(ExpectedConditions.visibilityOfElementLocated(By.id("descriptionInput")));
    input_desc.clear();
    input_desc.sendKeys("Description");
}catch(Throwable e){
    System.err.println("Description field wasn't found. "+e.getMessage());
}

或者将Implict wait增加到10秒:

_driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);