Protractor clear() not working

前端 未结 5 673
心在旅途
心在旅途 2021-01-03 21:39

I have two tests:

  it(\'should filter the phone list as user types into the search box\', function() {

    var results = ptor.findElements(protractor.By.re         


        
相关标签:
5条回答
  • 2021-01-03 22:22

    You can combine promisses into a chain:

    queryInput.clear().sendKeys('nexus');

    0 讨论(0)
  • 2021-01-03 22:26

    The Documentation of clear() says the following:

    [ !webdriver.promise.Promise ] clear( )

    Schedules a command to clear the {@code value} of this element. This command has no effect if the underlying DOM element is neither a text INPUT element nor a TEXTAREA element.

    Returns: A promise that will be resolved when the element has been cleared.

    so in order to get clear to do what you want, you have to work with the promise that it returns! to do so you have to use then()

    here is how it works:

    queryInput.clear().then(function() {
        queryInput.sendKeys('motorola');
    })
    

    so clear() returns you a promise to clear the input and then() tells the promise what to do as soon as the input is cleared.

    0 讨论(0)
  • 2021-01-03 22:27

    Clear().then(..) doesn't work for me.

    So this is my work around:

    queryInput.sendKeys(protrator.Key.chord(protrator.Key.CONTROL, 'a'));
    queryInput.sendKeys('nexus')
    
    0 讨论(0)
  • 2021-01-03 22:46
    await element.sendKeys(Key.chord(Key.CONTROL, 'a'));
    
    await element.sendKeys(Key.DELETE);
    
    0 讨论(0)
  • 2021-01-03 22:46

    Using PageObject pattern and async/await, I have such code that works:

    async clearForm() {
        await this.nameInput.clear();
        await this.descriptionInput.clear();
    }
    
    0 讨论(0)
提交回复
热议问题