-1

I have filled in an input field in an application under test. Now I want to validate that the fields entered are correctly saved by editing the form. I want to achieve this using Selenium.

Can someone suggest the approach and complete code like how to proceed with it?

2 Answers 2

0

Solution :

  • Filling the form using selenium
String user = Narendra;
WebElement name = driver.findElement(By.id("Narendra"));
  • Form submission could be done like:
WebElement submit = driver.findElement(By.id("SubmitButton")).submit();
  • To verify the entered value after form submission would be like
String actualFilledName = driver.findElement(By.id("actualFilledName")).getText();

AssertTrue(user, actualFilledName);

OR

browser.get("https://www.python.org/")
content=browser.page_source

result = content.find('Narendra')

Note - For further refer this

0

To verify the fields filled in an application using Selenium, you can follow these steps:

  1. Launch the browser and navigate to the application's URL.
  2. Fill in the input fields with the desired data.
  3. Click the "Submit" or "Save" button to submit the form.
  4. Verify that the data is saved correctly by navigating to the edit form page.
  5. Retrieve the data from the input fields on the edit form page.
  6. Compare the retrieved data with the original data that was entered in step 2.

Here is a sample code (Selenium with Java) to get you started:

import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver;

public class FormTest { public static void main(String[] args) { // Set up WebDriver and navigate to the application System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver"); WebDriver driver = new ChromeDriver(); driver.get("http://your-application-url.com");

    // Fill out and save the form
    WebElement nameField = driver.findElement(By.id("name"));
    nameField.sendKeys("John Doe");

    WebElement emailField = driver.findElement(By.id("email"));
    emailField.sendKeys("[email protected]");

    WebElement saveButton = driver.findElement(By.id("save-button"));
    saveButton.click();

    // Edit the form and verify the updated information
    WebElement editButton = driver.findElement(By.id("edit-button"));
    editButton.click();

    WebElement newNameField = driver.findElement(By.id("name"));
    newNameField.clear();
    newNameField.sendKeys("Jane Doe");

    WebElement newEmailField = driver.findElement(By.id("email"));
    newEmailField.clear();
    newEmailField.sendKeys("[email protected]");

    saveButton.click();

    String updatedName = driver.findElement(By.id("name")).getAttribute("value");
    String updatedEmail = driver.findElement(By.id("email")).getAttribute("value");

    if (updatedName.equals("Jane Doe") && updatedEmail.equals("[email protected]")) {
        System.out.println("Form updated successfully.");
    } else {
        System.out.println("Form update failed.");
    }

    driver.quit();
}

}

You will need to replace the /path/to/chromedriver with the actual path to the ChromeDriver file on your machine, and update the element selectors (e.g. By.id("name"), By.id("email"), etc.) to match those in your application.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.