javascriptjavaseleniumautosuggestcoveo

I need to verify that suggestion list in coveo's search suggests correctcly


So, yes, I tried to locate suggestion magic box by css selector in Selenium, tried to send DOWN key to select suggested values, tried to find element's tag by JavaScript but nothing helps. All that I found is that element lay somewhere here.

div[class='magic-box-suggestion coveo-omnibox-selectable']

But trying to get all children from that element return 0 elements. I tried to Google that problem, but didn't found anything.


Solution

  • I've got a solution! Here we are:

    driver.findElements(By.xpath("//div[./span[@class='coveo-omnibox-hightlight']]"));
    

    This code returns List<WebElement> that contains all span elements in Coveo's magic-box-suggestions.

    This JavaScript code helped me to find a locator for Coveo's autosuggestion query. Just execute this in the browser's console.

    // select the target node
    var target = document.querySelector('div.magic-box-suggestions');
    
    // create an observer instance
    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            console.log(mutation);
        });    
    });
    
    // configuration of the observer:
    var config = { attributes: true, childList: true, characterData: true }
    
    // pass in the target node, as well as the observer options
    observer.observe(target, config);