【问题标题】:Changing Password Automation / Selenium更改密码自动化 / Selenium
【发布时间】:2017-11-22 08:12:30
【问题描述】:

我正在研究 Java 中的自动化。我正在从“test.properties”文件中获取数据。我想从用户设置面板更改网站上的密码。有一些元素;

  • 第一次输入:旧密码
  • 第二次输入:新密码
  • 第三次输入:新密码重复
  • 提交:保存

我怎样才能为此创建适当的自动化?

【问题讨论】:

  • 请编辑问题以将其限制为具有足够详细信息的特定问题,以确定适当的答案。避免一次问多个不同的问题。请参阅How to Ask 页面以获得澄清此问题的帮助。

标签: java selenium


【解决方案1】:

如果我理解正确,这些是您应该遵循的步骤:

  1. 创建一个测试类。

  2. 在进入测试用例 (@Before) 之前初始化您的网络驱动程序(Chrome 或 Firefox)

  3. driver.get(https://<your_website>)

  4. 找到您的输入并提交按钮:

    @FindBy(id = "<your_form>:<password>")
    private WebElement textPassword;`
    
    @FindBy(id = "<your_form>:<submitButton>")
    private WebElement submitButton;`
    
  5. 向网络元素发送密钥:

    textPassword.sendKeys(<your_password>)
    
  6. 点击提交

    submitButton.click();
    

你可以在softwaretesting.com找到一个很好的教程

【讨论】:

    【解决方案2】:

    使用以下代码通过脚本更改密码,

    import java.util.concurrent.TimeUnit;
    
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    
    public class ChangePassword
    {
         public static void main(String[] args) 
         {
                System.setProperty("webdriver.chrome.driver","specify your chromedriver.exe path here");
                WebDriver driver = new ChromeDriver();
                String URL = "Your site url";
                driver.get(URL);
                driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    
                //Old Password
                driver.findElement(By.xpath("Old Password Field xpath here")).sendKeys("old password");
                driver.findElement(By.xpath("New Password Field xpath here")).sendKeys("new password");
                driver.findElement(By.xpath("Re-enter Password Field xpath here")).sendKeys("new password");
                driver.findElement(By.xpath("Submit button xpath")).click();
       }     
    }
    

    【讨论】:

      猜你喜欢
      • 2020-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-30
      相关资源
      最近更新 更多