由于多个输入元素,ElementNotVisibleException

时间:2017-08-25 15:54:25

标签: cucumber-jvm geb web-testing

我有一个geb-cucumber场景,在某些时候尝试在Frame的输入字段中插入一个字符串。

问题在于框架由于某种原因具有许多相同的输入(!!),看起来像

<input aria-labeledby="userid-label" aria-required="true" autocomplete="off" class="error input" tabindex="51" type="text" id="el3fd4c7bd50db061c" maxlength="48" aria-invalid="true" aria-describedby="gwt-uid-63">
<input aria-labeledby="userid-label" aria-required="true" autocomplete="off" class="error input" tabindex="51" type="text" id="el3fd4c7bd50db061c" maxlength="48" aria-invalid="true" aria-describedby="gwt-uid-63">
<input aria-labeledby="userid-label" aria-required="true" autocomplete="off" class="error input" tabindex="51" type="text" id="el3fd4c7bd50db061c" maxlength="48" aria-invalid="true" aria-describedby="gwt-uid-63">

在Chrome devtools控制台中如果我给$(“input [name = xxx])它返回elem然后继续抛出以下消息

VM5451:1 Uncaught SyntaxError: Unexpected token # in JSON at position 0
    at JSON.parse (<anonymous>)
    at i (application-2a3801d….js:11)

这可能无关紧要,因为我的目的是获取元素并插入一个字符串。

getArrayField(userIdField) << "aabbcc"

getArrayField似乎试图解决这个问题,但它确实没有用。

测试失败,出现以下堆栈跟踪

org.openqa.selenium.ElementNotVisibleException: element not visible
  (Session info: chrome=60.0.3112.113)
  (Driver info: chromedriver=2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5),platform=Linux 4.11.12-200.fc25.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.5.2', revision: '10229a9', time: '2017-08-21T17:29:55.15Z'
System info: host: 'iob-4finance', ip: '192.168.175.6', os.name: 'Linux', os.arch: 'amd64', os.version: '4.11.12-200.fc25.x86_64', java.version: '1.8.0_131'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5), userDataDir=/tmp/.org.chromium.Chromium.2ksxEt}, takesHeapSnapshot=true, pageLoadStrategy=normal, unhandledPromptBehavior=, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=60.0.3112.113, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: 85a17386757827e393d4f83772a88959

    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.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:82)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:45)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:641)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:275)
    at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:99)
    at geb.navigator.NonEmptyNavigator$_leftShift_closure30.doCall(NonEmptyNavigator.groovy:448)
    at geb.navigator.NonEmptyNavigator.leftShift(NonEmptyNavigator.groovy:447)
    at geb.content.TemplateDerivedPageContent.leftShift(TemplateDerivedPageContent.groovy:27)
    at com.ofg.loans.dk.at.web.site.pages.IdentificationPage.logIntoNemIdApp(IdentificationPage.groovy:40)
    at com.ofg.loans.dk.at.web.site.pages.IdentificationPage$logIntoNemIdApp.call(Unknown Source)
    at com.ofg.loans.dk.at.web.site.stepdefs.nemid.NemIdStepDefs$_run_closure3.doCall(NemIdStepDefs.groovy:47)
    at ✽.And user logs into NemId from the webapp(com/at/web/features/.feature:13)

您还可以在https://service.nemid.nu/dk-en/#log_on_to_self-service处重现问题,这是使用的识别服务。我可以使用任何帮助或指导正确的解决方案。感谢

1 个答案:

答案 0 :(得分:0)

我没有在您的示例HTML中看到名称字段。但如果有名称字段,请尝试在Chrome开发者工具中使用此字段:

$("input[name='xxx']")

这是在Geb:

$("input", name: "xxx")

此外,您似乎可能正在使用#作为名称的一部分。确保使用\#

转义角色

另一种选择是,如果元素总是以相同的顺序排列,则可以使用eq selector

$("input[name='xxx']").eq(0)