Как проверить, что раскрывающееся меню открыто с использованием селена для Java? - PullRequest
0 голосов
/ 27 октября 2019

Я пытаюсь проверить в одном из моих тестов, если раскрывающееся меню уже открыто: enter image description here

В случае, если раскрывающееся меню открыто, я хотел бы знать оон (работает от Дженкинса) и, соответственно, закройте или откройте его.

Вот как выглядит элемент выпадающего меню:

<button class="jss14 jss123 jss125 jss128 jss120" tabindex="0" type="button" qa-id="qa-filter-labels-button"><span class="jss124"><span class="jss121">All Labels</span><svg class="jss34 jss122" focusable="false" viewBox="0 0 24 24" aria-hidden="true" role="presentation" style="float: right;"><path d="M7 10l5 5 5-5z"></path><path fill="none" d="M0 0h24v24H0z"></path></svg></span><span class="jss43"></span></button>

Я изо всех сил пытаюсь найти правильный способ проверкираскрывающееся меню закрыто или открыто.

РЕДАКТИРОВАТЬ (раскрывающееся меню HTML):

<div class="jss149"><div class="jss724 jss721"><div class="jss99 jss86 jss100 jss87 jss104 jss722 qa_filter_search_input"><input aria-invalid="false" class="jss109 jss94 jss115" placeholder="Search" type="text" qa-id="qa-filter-labels-search-input" value=""><div class="jss116 jss119"><svg class="jss34 jss723 qa_filter_search_btn" focusable="false" viewBox="0 0 24 24" aria-hidden="true" role="presentation"><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path><path fill="none" d="M0 0h24v24H0z"></path></svg></div></div></div><div class="jss728" style="height: 144px;"><div class="jss729" qaid="qa-filter-labels-list" style="height: 96px;"><div class="jss730" title="system-all" qaid="qa-filter-labels-system-all-line"><span class="jss732"><span class="jss14 jss8 jss741 jss735 jss739 jss734"><span class="jss13"><svg class="jss34" focusable="false" viewBox="0 0 24 24" aria-hidden="true" role="presentation"><path d="M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z"></path></svg><input class="jss744" type="checkbox" data-indeterminate="false" qaid="qa-filter-labels-system-all-checkbox" value="system-all"></span><span class="jss43"></span></span></span><span class="jss731" qaid="qa-filter-labels-system-all-span">system-all</span></div><div class="jss730" title="system-f5" qaid="qa-filter-labels-system-f5-line"><span class="jss732"><span class="jss14 jss8 jss741 jss735 jss739 jss734"><span class="jss13"><svg class="jss34" focusable="false" viewBox="0 0 24 24" aria-hidden="true" role="presentation"><path d="M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z"></path></svg><input class="jss744" type="checkbox" data-indeterminate="false" qaid="qa-filter-labels-system-f5-checkbox" value="system-f5"></span><span class="jss43"></span></span></span><span class="jss731" qaid="qa-filter-labels-system-f5-span">system-f5</span></div></div></div><div class="jss745"><button class="jss14 jss15 jss123 jss125 jss128 jss143 jss747" tabindex="-1" type="button" disabled="" qa-id="qa-filter-labels-reset"><span class="jss124 jss750">Reset All</span></button><button class="jss14 jss123 jss125 jss126 jss128 jss129 jss746" tabindex="0" type="button" qa-id="qa-filter-labels-apply"><span class="jss124">Apply</span><span class="jss43"></span></button></div></div>

код, который я пробовал:

void selectUlMenu(String type,By applyBth, String... items) {
        LOG.i("Clicking on filter menu inside cpmbobox selection type="+type+" and items= " + Arrays.toString(items));
        if(isEnabled(applyBth)){
            clickButton(applyBth);
        }else {
            clickOnArrowDropDownButton();
            sleep(Duration.FIVE_HUNDRED_MILLISECONDS);
            for (String item : items) {
                clickButton(createCssSelector(type, item));
            }
        }

Полный HTML Код меню:

<div class="jss81"><div style="width: 165px;"><div class="jss99 jss86 jss83 jss104"><input class="jss109 jss94 jss82 jss115" placeholder="Search" type="text" qa-id="qa_search_box" value=""><div class="jss116 jss119 jss84"><svg class="jss34 jss85" focusable="false" viewBox="0 0 24 24" aria-hidden="true" role="presentation"><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path><path fill="none" d="M0 0h24v24H0z"></path></svg></div></div></div><button class="jss14 jss123 jss125 jss128 jss120" tabindex="0" type="button" qa-id="qa-filter-devices-button"><span class="jss124"><span class="jss121">All Devices</span><svg class="jss34 jss122" focusable="false" viewBox="0 0 24 24" aria-hidden="true" role="presentation" style="float: right;"><path d="M7 10l5 5 5-5z"></path><path fill="none" d="M0 0h24v24H0z"></path></svg></span><span class="jss43"></span></button><button class="jss14 jss123 jss125 jss128 jss120" tabindex="0" type="button" qa-id="qa-filter-labels-button"><span class="jss124"><span class="jss121">All Labels</span><svg class="jss34 jss122" focusable="false" viewBox="0 0 24 24" aria-hidden="true" role="presentation" style="float: right;"><path d="M7 10l5 5 5-5z"></path><path fill="none" d="M0 0h24v24H0z"></path></svg></span><span class="jss43"></span></button><button class="jss14 jss123 jss125 jss128 jss120" tabindex="0" type="button" qa-id="qa-filter-severities-button"><span class="jss124"><span class="jss121">All Severities</span><svg class="jss34 jss122" focusable="false" viewBox="0 0 24 24" aria-hidden="true" role="presentation" style="float: right;"><path d="M7 10l5 5 5-5z"></path><path fill="none" d="M0 0h24v24H0z"></path></svg></span><span class="jss43"></span></button><button class="jss14 jss123 jss125 jss128 jss120" tabindex="0" type="button" qa-id="qa-filter-statuses-button"><span class="jss124"><span class="jss121">All Statuses</span><svg class="jss34 jss122" focusable="false" viewBox="0 0 24 24" aria-hidden="true" role="presentation" style="float: right;"><path d="M7 10l5 5 5-5z"></path><path fill="none" d="M0 0h24v24H0z"></path></svg></span><span class="jss43"></span></button><button class="jss14 jss123 jss125 jss128 jss120" tabindex="0" type="button" qa-id="qa-filter-users-button"><span class="jss124"><span class="jss121">All Users</span><svg class="jss34 jss122" focusable="false" viewBox="0 0 24 24" aria-hidden="true" role="presentation" style="float: right;"><path d="M7 10l5 5 5-5z"></path><path fill="none" d="M0 0h24v24H0z"></path></svg></span><span class="jss43"></span></button></div>

1 Ответ

0 голосов
/ 27 октября 2019

Приведенный ниже код должен щелкать меню, полученное по тексту, вводить текст для поиска, выбирать фильтруемый элемент и нажимать «применить»:

public void selectUIMenu(String menu, String... items) {
    WebDriverWait wait = new WebDriverWait(driver, 10);

    if (driver.findElements(By.cssSelector("[title='" + items[0] + "']")).stream().noneMatch(WebElement::isDisplayed)) {
        wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("//button[.='" + menu + "']"))).click();
    }

    WebElement searchInput = wait.until(d -> {
        List<WebElement> searchInputs = d.findElements(By.cssSelector("[qa-id*='search-input']"));
        List<WebElement> visibleInputs = searchInputs.stream().filter(WebElement::isDisplayed).collect(Collectors.toList());
        return visibleInputs.size() > 0 ? visibleInputs.get(0) : null;
    });

    for (String item : items) {
        searchInput.clear();
        searchInput.sendKeys(item);
        wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("[title='" + item + "']"))).click();
        // or
        // wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("input[value='" + label + "']"))).click();
    }
    driver.findElements(By.cssSelector("//button[.='Apply']"))
            .stream()
            .filter(WebElement::isDisplayed)
            .findFirst().orElseThrow().click();

}
...