无法识别Selenium webdriver for IE9中的元素

时间:2015-12-31 15:45:03

标签: selenium selenium-webdriver

我无法使用Selenium webdriver识别页面中的任何元素。使用2.48.0 selenium jar。我试过xpath绝对,相对路径,css选择器,id,名称。全部抛出NoSuchElementException。我被困在这里。请帮我。我可以轻松登录应用程序登录后选择一个菜单项将指向一个页面。在该页面上,将无法识别任何元素。

请找到我想要输入的文本框 html来源:

<input class="AnswerText" type="text" onblur="$('#ind6').attr('class','ALIP-Icon sprite-icon_indicator_off'); " onfocus="gotFocus(this);$('#ind6').attr('class','ALIP-Icon sprite-icon_indicator'); removeFocus('ind6'); " maxlength="15" size="15" value="" name="7:/XML/ApplicationSummary/ContractNumber">

控制台错误错误:

Started InternetExplorerDriver server (64-bit)
2.48.0.0
Listening on port 43801
org.openqa.selenium.NoSuchElementException: Unable to find element with xpath == /html/body/div/div/div/form/div[1]/table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr/td[2]/div[2]/span/table/tbody/tr[1]/td[1]/div/div/table/tbody/tr/td[3]/input (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 377 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: host: 'V-INFSY-NBA121', ip: '172.30.1.102', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{browserAttachTimeout=0, enablePersistentHover=false, ie.forceCreateProcessApi=false, pageLoadStrategy=normal, ie.usePerProcessProxy=false, ignoreZoomSetting=true, handlesAlerts=true, version=9, platform=WINDOWS, nativeEvents=false, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:43801/, takesScreenshot=true, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=dismiss}]
Session ID: 38d52e22-4575-49b3-aaf4-25a96a7d177a
*** Element info: {Using=xpath, value=/html/body/div/div/div/form/div[1]/table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr/td[2]/div[2]/span/table/tbody/tr[1]/td[1]/div/div/table/tbody/tr/td[3]/input}
    at sun.reflect.GeneratedConstructorAccessor9.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:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:353)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:490)
    at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:345)
    at com.onfs.test.CommonMethods.type(CommonMethods.java:558)
    at com.onfs.test.Application_Entry.testMethod(Application_Entry.java:83)
    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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

2 个答案:

答案 0 :(得分:1)

我认为存在同步问题。我会在开始发送值之前等待该元素出现。请使用以下代码并尝试运行。它应该工作。

我将xpath替换为名称,或者您也可以尝试使用Class。你有很大的xpath。在我看来,这么长时间并不好。

    WebDriverWait wait = new WebDriverWait(driver, timeoutWait);
                wait.until(ExpectedConditions.visibilityOf(By.name("7:/XML/ApplicationSummary/ContractNumber"))).sendKeys("1234567")
  

WebDriverWait

的详细文档

答案 1 :(得分:0)

您可以通过禁用保护模式来尝试相同的操作吗?让我们在下面进行操作,如果您仍然面临并且还提供代码,我可能知道什么是问题

  1. 转到IEDriverServer.exe 32位并使用相同的
  2. 取消选中安全标签中的所有区域
  3. 尝试使用另一个答案中指定的短xpath(如果您的工作不起作用)
  4. 首先尝试不等待,如果失败则等待,然后执行thread.sleep
  5. 感谢