Значение в поле ввода не сохраняется в Selenium JavaJAVA

Программисты JAVA общаются здесь
Anonymous
Значение в поле ввода не сохраняется в Selenium Java

Сообщение Anonymous »

Это вводные данные, над которыми я борюсь

Total Proposal Cost(INR):*











Здесь поле ввода отключено. При записи xpath из selectorshub отображается предупреждение «Поле ввода отключено, разрешите ему вводить значение». Я использовал исполнитель javascript, чтобы включить поле. и введите значение, но после сохранения данных и перехода на следующую страницу значение отображается как 0. В консоли также нет ошибки.
Я пытаюсь сохранить значение 70000, но при переходе на следующую страницу там и на предыдущей странице отображается 0.
Это мой код:
Это мой код:
// 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.");
}



Подробнее здесь: https://stackoverflow.com/questions/785 ... enium-java

Вернуться в «JAVA»