【问题标题】:Unable to identify elements in Selenium webdriver for IE9无法识别 IE9 的 Selenium webdriver 中的元素
【发布时间】:2016-04-05 13:18:39
【问题描述】:

我无法使用 Selenium webdriver 识别页面中的任何 web 元素。使用 2.48.0 硒罐。我尝试过 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)

【问题讨论】:

  • 你能添加那个 HTML 代码吗?
  • 这是我尝试使用的代码 driver.findElement(By.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")).sendKeys("1234567");

标签: selenium selenium-webdriver


【解决方案1】:

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

  1. 选择 IEDriverServer.exe 32 位并使用相同
  2. 取消选中安全选项卡中的所有区域
  3. 如果您的答案不起作用,请尝试在另一个答案中指定的短 xpath
  4. 先尝试不等待,等待,如果失败则 thread.sleep

谢谢

【讨论】:

    【解决方案2】:

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

    我将 xpath 替换为名称,或者您也可以尝试使用 Class。你有非常大的xpath。在我看来,有那么长是不好的。

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

    WebDriverWait的详细文档

    【讨论】:

    • 感谢波士顿的回复。它很有效果。我使用了下面的代码 WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("7:/XML/ApplicationSummary/ContractNumber"))).sendKeys("1234567");它收到错误消息。这类似于 noSuchElementException。即使我尝试使用 javascript executescript 方法进行设置,仍然得到 NoSuchElementException。该页面中的所有元素都未被识别。很奇怪。
    • 我认为您正在使用 selenium 服务器。请尝试在本地运行并查看它是否正在执行,然后尝试运行此代码。您可以轻松调试。如果需要,您需要添加更多时间。最多 1 分钟。
    • org.openqa.selenium.TimeoutException:10 秒后超时等待 By.name 定位的元素的可见性:7:/XML/ApplicationSummary/ContractNumber 构建信息:版本:'2.48.2' ,修订:'41bccdd',时间:'2015-10-09 19:59:12' 系统信息:主机:'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'
    • 10 秒是非常少的时间。如果元素没有出现,则意味着它可能在 iframe 后面:stackoverflow.com/questions/24247490/…
    • 硒服务器?你的意思是硒服务器独立2.48.jar导致这个问题?什么是替代 jar 用于代替 Java 的 selenium 服务器
    猜你喜欢
    • 2013-09-20
    • 1970-01-01
    • 1970-01-01
    • 2016-04-14
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多