Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a fallback for clearValue command.. #4064

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions lib/transport/selenium-webdriver/method-mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const NightwatchLocator = require('../../element/locator-factory.js');
const {isString} = require('../../utils');
const fs = require('fs');
const cdp = require('./cdp.js');

const {Key} = require('selenium-webdriver');
const {element_command_retries} = require('../../settings/defaults.js');
module.exports = class MethodMappings {
get driver() {
return this.transport.driver;
Expand Down Expand Up @@ -578,16 +579,28 @@ module.exports = class MethodMappings {

async isElementSelected(webElementOrId) {
const element = this.getWebElement(webElementOrId);
await element.clear();
const value = await element.isSelected();

return value;
},
async clearElementValue(webElementOrId, text) {
try {
const element = this.getWebElement(webElementOrId);
await element.clear(); // Clear the element's value (if it's an input field)

// Check if the element still has some value
let value = await element.getAttribute('value');
while (value !== null && value !== '') {
await element.sendKeys(Key.BACK_SPACE); // Send BACK_SPACE keys to cleared the value
value = await element.getAttribute('value'); // Update the value after sending the BACK_SPACE
}

async clearElementValue(webElementOrId) {
const element = this.getWebElement(webElementOrId);
await element.clear();

return null;
// Once the element is cleared, send the new text
await element.sendKeys(text);
} catch (error){
console.error('An error occurred', error);
}
},

setElementValueRedacted(...args) {
Expand Down
16 changes: 16 additions & 0 deletions test/clearValueTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
describe('clearValue Demo', function() {
before(browser => {
browser
.navigateTo('https://sandbox.mabl.com/mailbox');
});

it('shows issue with clearValue command', async function(browser) {
browser
.sendKeys('input[name=to]', 'hello')
.clearValue('input[name=to]')
.sendKeys('input[name=to]', 'hi')
.pause(3000);
});

after(browser => browser.end());
});