This is my snippet:
<div class="row ">
<div
class="col-md-12 col-lg-12 col-sm-12 col-xs-12 form-group col-md-push-2 col-sm-push-1">
<div
class="col-md-2 col-lg-2 col-sm-2 col-xs-12 text-justify">
<label class="label-class">Total Proposal Cost(INR):<span
style="color: red;">*</span></label>
</div>
<div class="col-md-6 col-lg-6 col-sm-6 col-xs-12">
<div class="input-container">
<input id="totalProposalCost" name="totalProposalCost" class="input-field validateAmt " value="0" onblur="saveField('totalProposalCost')" type="text" value="0.0"/>
</div>
</div>
</div>
</div>
The input field is disabled here, on writing the xpath from selectorshub it shows an alert saying “Input box is disable, enable it to enter value” i have used javascript executor to enable to box and enter the value but after saving the details and moving to the next page, the value is shown 0. in the console also there is not error.
I am trying to retain the value70000 but on moving to the next page it shows 0 there and in the previous page also.
This is my code:
This is my code:
// Locate the input field
WebElement inputField = driver.findElement(By.id("totalProposalCost"));
// Wait until the input field is visible and interactable
WebDriverWait w1 = new WebDriverWait(driver, Duration.ofSeconds(20));
w1.until(ExpectedConditions.visibilityOf(inputField));
// Enable the input field if it is disabled
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0, 500);");
js.executeScript("arguments[0].removeAttribute('disabled');", inputField);
// Set the value using JavaScript and dispatch events
String valueToSet = "70000";
js.executeScript(
"arguments[0].value = arguments[1];" +
"arguments[0].dispatchEvent(new Event('input'));" +
"arguments[0].dispatchEvent(new Event('change'));" +
"arguments[0].focus();" + // Focus on the element
"arguments[0].blur();", // Trigger blur event
inputField, valueToSet
);
// Wait and verify that the value is set correctly
w1.until(ExpectedConditions.attributeToBe(inputField, "value", valueToSet));
String fieldValue = inputField.getAttribute("value");
System.out.println("Field Value: " + fieldValue); // Should print "YOUR_VALUE"
Thread.sleep(10000);
// Proceed with the next steps if the value is set correctly
if (fieldValue.equals(valueToSet)) {
// Continue with the next steps (e.g., submitting the form or navigating to the next page)
driver.findElement(By.xpath("//input[@id='collaborativeCheck']")).click();
System.out.println("Value was set correctly.");
} else {
System.out.println("Value was not set correctly.");
}
Mohita Mudaliar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.