2017-08-25 84 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)