首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >希望编辑在应用程序中填写的表单,并需要验证填充的字段在Selenium中是正确的

希望编辑在应用程序中填写的表单,并需要验证填充的字段在Selenium中是正确的
EN

Stack Exchange QA用户
提问于 2023-02-15 15:08:27
回答 1查看 83关注 0票数 -1

我已经在被测试的应用程序中填写了一个输入字段。现在,我希望通过编辑表单来验证输入的字段是否正确保存。我希望使用Selenium来实现这一点。

有人能给出方法和完整的代码建议,比如如何继续吗?

EN

回答 1

Stack Exchange QA用户

发布于 2023-02-16 06:10:11

要验证使用Selenium填充的应用程序中的字段,可以执行以下步骤:

  1. 启动浏览器并导航到应用程序的URL。
  2. 用所需的数据填写输入字段。
  3. 单击“提交”或“保存”按钮提交表单。
  4. 通过导航到“编辑表单”页,验证数据保存是否正确。
  5. 从编辑表单页的输入字段中检索数据。
  6. 将检索到的数据与步骤2中输入的原始数据进行比较。

下面是一个示例代码()让您开始工作:

进口org.openqa.selenium.By;进口org.openqa.selenium.WebDriver;进口org.openqa.selenium.WebElement;进口org.openqa.selenium.chrome.ChromeDriver;

公共类FormTest { public静态void (String[] args) { //设置WebDriver并导航到应用程序System.setProperty("webdriver.chrome.driver","/path/ to /chromedriver");WebDriver驱动程序=新ChromeDriver();driver.get(“http://your-application-url.com“”);

代码语言:javascript
复制
    // 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("johndoe@example.com");

    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("janedoe@example.com");

    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("janedoe@example.com")) {
        System.out.println("Form updated successfully.");
    } else {
        System.out.println("Form update failed.");
    }

    driver.quit();
}

}

您需要将/path/to/chromedriver替换为机器上的ChromeDriver文件的实际路径,并更新元素选择器(例如,By.id("name")By.id("email")等)。以匹配您的应用程序中的内容。

票数 0
EN
页面原文内容由Stack Exchange QA提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://sqa.stackexchange.com/questions/51267

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档