question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I.clearField and I.fillField not working as expected.

See original GitHub issue

What are you trying to achieve?

Replace text in field using I.fillField or clearing text with I.clearField.

What do you get instead?

If the field has the following text already in it: “hello” and I try to replace with “world” I get “helloworld”. If I try to use I.clearField the text in the field does not change.

Provide console output if related. Use --verbose mode for more details.

No errors thrown.

Provide test source code if related

I.clearField(selectors.name);
I.fillField(selectors.name, name);

Details

  • CodeceptJS version: 6.2
  • NodeJS Version: v7.8.0
  • Operating System: MacOS Sierra v10.12.4
  • Nightmare version: 2.10.0
  • Nightmare Upload version: 0.1.1
  • Configuration file:
{
  "output": "./output",
  "helpers": {
    "nightmare": {
      "url": "http://localhost:1079",
      "restart": true,
      "show": true,
      "typeInterval": 5,
      "windowSize": "1440x1024"
    }
  },
  "include": {
    "I": "./e2e-tests/steps/steps.js"
  },
  "mocha": {
    "reporterOptions": {
        "reportDir": "output"
    }
  },
  "bootstrap": false,
  "teardown": null,
  "hooks": [],
  "tests": "./e2e-tests/tests/**/*_test.js",
  "timeout": 10000,
  "name": "testing"
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
gggusercommented, Jul 23, 2019

Same issue, is there any update on this?

You can use this custom step, works perfectly:

Add to steps_file.js:

    updateField(fieldName, value) {
      this.appendField(fieldName, '');
      this.pressKey(['Shift', 'Home']);
      this.pressKey('Backspace');
    }
7reactions
kennasoftcommented, Dec 19, 2018

@jmitchell89 is correct, that this affects react projects, as I’ve also observed. I created a custom helper, which solves the problem. Add this to your custom_steps.js (or whatever you named it) file:

'use strict';
module.exports = function() {
  return actor({ 
    ... // other custom helpers
    clearReactField: async function(locator) {
      this.doubleClick(locator);      // set focus on element found by locator and highlight content
      this.pressKey('Backspace');  // delete content of element
    }
  });
}

Then you can do for example:

const assert = require('assert');
Feature('"Edit Field"');

Scenario('locate and edit text field', async (I) => {
    // do other things
    const oldText = await I.grabTextFrom('#form1 input[type="text"]');
    I.clearReactField('#form1 input[type="text"]');
    I.fillField('#form1 input[type="text"]', `${oldText} has been Edited!`);
    I.wait(1);
    const newText = await I.grabTextFrom('#form1 input[type="text"]');
    assert.ok(newText === `${oldText} has been Edited!`, 'Old Text was cleared and replaced successfully');
    // do more things
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Codeception with Webdriver $I->fillField not working although ...
Finally found an answer - there was some unknown hidden element which matched the same selector and this element caused an Exception:.
Read more >
clearField() not working in codeceptjs
I am clearing first field and entering data. Exm: I.clearField(this.fields.secATabLname); //xpath:this.fields.secATabLname I.fillField(this.
Read more >
WebDriver - CodeceptJS
Fills a text field or textarea, after clearing its value, with the given string. Field is located by name, label, CSS, or XPath....
Read more >
Protractor - CodeceptJS
Protractor helper is based on Protractor library and used for testing web ... strict locator I.fillField({css: 'form#login input[name=username]'}, 'John'); ...
Read more >
npm:@codeceptjs/detox-helper | Skypack
Testing Mobile Apps on iOS and Android can look like this: I.setLandscapeOrientation(); I.fillField ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found