0

I need to click on a oneselectmenu and select an item made of primefaces JSF using protractor js.

Heres my code:

  it ('should pesquisa', function () {
    browser.get('localhost:8080/myapp/geral.xhtml');    

    var agruparPorFocus = element(protractor.By.xpath('//div[@id="form-pesquisa:consultarPor_panel"]/div/ul/li[4]')).click();
    var agruparPorInput = element(protractor.By.id('form-pesquisa:consultarPor_input'));

   });

and I'm getting this error:

ElementNotVisibleError: Element is not currently visible and so may not be interacted with
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'Lilian-fx', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-53-generic', java.version: '1.8.0_45'
Driver info: driver.version: unknown
   Stacktrace:
     ElementNotVisibleError: Element is not currently visible and so may not be interacted with
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'Lilian-fx', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-53-generic', java.version: '1.8.0_45'
Driver info: driver.version: unknown
    at Array.forEach (native)
Error
    at [object Object].<anonymous> (/home/lilian-fx/workspace/protractor/fwLite/spec.fwl.js:60:115)
    at runMicrotasksCallback (node.js:337:7)
From: Task: Asynchronous test function: it()
Error
    at [object Object].<anonymous> (/home/lilian-fx/workspace/protractor/fwLite/spec.fwl.js:49:2)
    at Object.<anonymous> (/home/lilian-fx/workspace/protractor/fwLite/spec.fwl.js:5:1)

Finished in 17.565 seconds
5 tests, 4 assertions, 1 failure

that is the HTML code

<div class="ui-helper-hidden-accessible">
    <input id="form-pesquisa:consultarPor_focus" name="form-pesquisa:consultarPor_focus"
    autocomplete="off" type="text">
</div>
<div class="ui-helper-hidden-accessible">
    <select id="form-pesquisa:consultarPor_input" name="form-pesquisa:consultarPor_input"
    tabindex="-1" onchange="PrimeFaces.ab({s:'form-pesquisa:consultarPor',e:'change',p:'form-pesquisa:consultarPor'});">
        <option value="1">
            Meia Hora
        </option>
        <option value="2" selected="selected">
            Dia
        </option>
        <option value="3">
            Mês
        </option>
        <option value="4">
            Ano
        </option>
    </select>
</div>
<label style="width: 335px;" id="form-pesquisa:consultarPor_label" class="ui-selectonemenu-label ui-inputfield ui-corner-all">
    Dia
</label>
<div class="ui-selectonemenu-trigger ui-state-default ui-corner-right">
    <span class="ui-icon ui-icon-triangle-1-s ui-c">
    </span>
</div>
<li class="ui-selectonemenu-item ui-selectonemenu-list-item ui-corner-all"
data-label="Meia Hora">
    Meia Hora
</li>
<li class="ui-selectonemenu-item ui-selectonemenu-list-item ui-corner-all ui-state-highlight"
data-label="Dia">
    Dia
</li>
<li class="ui-selectonemenu-item ui-selectonemenu-list-item ui-corner-all"
data-label="Mês">
    Mês
</li>o
</li>o
</li>
<li class="ui-selectonemenu-item ui-selectonemenu-list-item ui-corner-all"
data-label="Ano">
    Ano
</li>

Can someone help?

1

The first line of issue log itself tells you what is happening.

ElementNotVisibleError: Element is not currently visible and so may not be interacted with

means that the protractor cannot find this element to interact with. This may be because the element may be visible on the browser after some time ( may be due to some AJAX call).

What I would suggest you is to have a kind of wait implemented so that you can wait for a specific period of time, until the element is visible and then access it.

I have never use Protractor, but a quick search tells me that you can use the ExpectedConditions to achieve this.

Here is a good link which tells you how you can implement a custom wait (called Explicit Wait) using the ExpectedConditions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.