Невозможно выбрать значение из раскрывающегося списка в динамической веб-таблице в Internet Explorer - PullRequest
0 голосов
/ 09 мая 2019

Я пытаюсь щелкнуть раскрывающийся список на веб-странице, которая находится внутри динамического веб-таблицы.

Я пытался найти и выбрать параметр, используя driver.findelement, actions.movetoElement, javascript, нажатие клавиши робота, но не повезло.

public void selectFromDropDown(String value) throws Exception
{

List<WebElement> elem = driver.findElements(By.xpath("//tbody[@id='tbodyAlternateIds']//select"));
        for(int i=1;i<elem.size()-1;i++) {
            System.out.println("Element Size>>>>>>>>" + elem.size());
            WebElement Identifiers = driver.findElement(By.xpath("//select[@id='alternateIds["+i+"].type.description']"));
            Select select = new Select(Identifiers);
            if(select.getFirstSelectedOption().getText().isEmpty()) {
                if(!(select.getFirstSelectedOption().getAttribute("value").equalsIgnoreCase(value))){
                    JavascriptExecutor js = (JavascriptExecutor) driver;
                    js.executeScript("document.getElementById('alternateIds["+i+"].type.description').value = "+value+";");
                }
            }

        }

    }

Мой DOM выглядит следующим образом


<SELECT id=alternateIds[2].type.description class=smalltext name=alternateIds[2].type.code value=""> 
<OPTION selected></OPTION> 
<OPTION value=AML>AML</OPTION> 
<OPTION value=ALC>Alacra ID</OPTION> 
<OPTION value=BOS>BOSS</OPTION> 
<OPTION value=BKA>Bankers Almanac ID</OPTION> 
`
`
`
`

</SELECT>

Сообщение об ошибке из журнала выглядит следующим образом:

org.openqa.selenium.JavascriptException: JavaScript error (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.5.3', revision: 'a88d25fe6b', time: '2017-08-29T12:42:44.417Z'
System info: host: 'VKRDAP0009714', ip: '30.206.79.17', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_202'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{browserAttachTimeout=0, enablePersistentHover=false, ie.forceCreateProcessApi=false, pageLoadStrategy=normal, unhandledPromptBehavior=dismiss, ie.usePerProcessProxy=false, ignoreZoomSetting=false, handlesAlerts=true, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=true, browserName=internet explorer, initialBrowserUrl=http://localhost:45547/, takesScreenshot=true, javascriptEnabled=true, ignoreProtectedModeSettings=false, platformName=WINDOWS, enableElementCacheCleanup=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=dismiss}]
Session ID: f0f347a8-b5c6-4bf1-bd89-576498a53872
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.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: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:646)
    at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:582)
    at com.bofa.ivv.application.driver.tandem.cucumber.step_definitions.CreateParty.selectFromDropDown(CreateParty.java:434)

Идентификатор в выбранном является динамическим.Я могу нажать на кнопку «Создать» и перейти к списку выпадающих списков.И, следовательно, каждый идентификатор выпадающего списка классифицируется и увеличивается на [1], [2] и т. Д. (AlternateIds [1] .type.description)

1 Ответ

0 голосов
/ 09 мая 2019
  1. Вам необходимо окружить value кавычками, такими как:

    js.executeScript("document.getElementById('alternateids[" + i + "].type.description').value='" + value + "'");
    
  2. Почему вообще вы собираетесь использовать этот вызов JavaScript?Существует Select.selectByValue () функция, которая делает то же самое
  3. Рассмотрите возможность переноса вашего теста для использования шаблона проектирования объектной модели страницы
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...