2017-08-25 83 views
0

我有一个geb-cucumber场景,它在某些时候尝试在一个帧的输入字段中插入一个字符串。ElementNotVisibleException由于多个输入元素

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

<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控制台如果我给$(“输入[名称= 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是用于识别服务。我可以使用任何帮助或方向来解决问题。谢谢

回答

0

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

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

而这盖布:

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

而且,看来你可能使用的是#作为的一部分名称。确保与\#

另一种选择逃跑的字符是如果这些元素总是以相同的顺序,你可以使用eq selector

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