user2092132
user2092132

Reputation: 137

How to reset the name of user in the field?

There is a table list of username, from these table I have edited the username "Pra" to "Pra1", but now when I come to the user table list its not finding a user with the name "Pra" because its updated with "Pra1". So, what I want is after updating an username in the search filter it search with updated username (With "Pra1"). Below are the running code upto the updated username please help me after that:

public class InsSystemCenter {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        WebDriver driver = new FirefoxDriver();
        driver.get("URL");

        driver.manage().timeouts().implicitlyWait(2, TimeUnit.MINUTES);

        // Verify the insfocus system center page has been opened or not by
        // xpath//

        if (driver.findElement(By.xpath("/html/body/table/tbody/tr[1]/td/h1")) != null) {
            System.out.println("Center has been opened");
        } else {
            System.out.println("Center is not displaying");
        }

        WebElement userName = driver.findElement(By.name("username"));
        userName.sendKeys("pra");

        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("123456");

        WebElement signIn = driver
                .findElement(By
                        .xpath("/html/body/table/tbody/tr[2]/td/table/tbody/tr[1]/td/form/center/div/table/tbody/tr[4]/td/input"));
        signIn.click();

        driver.manage().timeouts().implicitlyWait(2, TimeUnit.MINUTES);

        // Verify that welcome page is displayed or not//

        WebElement welcomePageVerify = driver
                .findElement(By
                        .xpath("/html/body/table/tbody/tr[3]/td/table/tbody/tr[1]/td/div[2]/span"));
        if (welcomePageVerify.isDisplayed()) {
            System.out.println("Welcome page is displaying");
        } else {
            System.out.println("Welcome page is not displaying");
        }

        // Try to click on the tab name "Settings" by xpath//

        WebElement settings = driver.findElement(By
                .xpath("/html/body/table/tbody/tr[2]/td/ul/li[3]/a"));
        settings.click();

        // Verifying that after clicking on "Setting" it opens a database page
        // or not//

        WebElement settingsVerify = driver
                .findElement(By
                        .xpath("/html/body/form/table/tbody/tr[3]/td/table/tbody/tr[1]/td[2]/div/table/tbody/tr/td[2]/h1/span"));
        if (settingsVerify.isDisplayed()) {
            System.out
                    .println("Database page is displayed after clicking on Setting tab");
        } else {
            System.out.println("Database page is not displaying");
        }

        driver.manage().timeouts().implicitlyWait(2, TimeUnit.MINUTES);

        // Click on the button "Users" by xpath, so that it goes to the page
        // where it show the list of users //

        WebElement users = driver
                .findElement(By
                        .xpath("/html/body/form/table/tbody/tr[3]/td/table/tbody/tr[1]/td[1]/p/a[2]"));
        users.click();

        // Verifying for users page opened or not//

        WebElement usersPageVerify = driver
                .findElement(By
                        .xpath("/html/body/table/tbody/tr[3]/td/table/tbody/tr[1]/td[2]/div/table/tbody/tr/td[2]/h1"));
        if (usersPageVerify.isDisplayed()) {
            System.out
                    .println("Users page is displayed after clicking on users button");
        } else {
            System.out.println("Users page is not displaying");
        }

        driver.manage().timeouts().implicitlyWait(2, TimeUnit.MINUTES);


        System.out.println("Total time take " + new Date());
        try {
            Thread.sleep(15000);
        } catch (InterruptedException e) {
            System.out.println("Error in wait");
        }
        driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
        System.out.println("Total time take " + new Date());

        WebElement usUserName = driver.findElement(By.id("g_UserName"));
        usUserName.sendKeys("Pra");
        usUserName.sendKeys(Keys.ENTER);
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            System.out.println("Error in wait");
        }
        usUserName.sendKeys(Keys.TAB);
        System.out.println("Total time take " + new Date());
        try {
            Thread.sleep(15000);
        } catch (InterruptedException e) {
            System.out.println("Error in wait");
        }


        driver.manage().timeouts().implicitlyWait(1, TimeUnit.MINUTES);

        // Checked the checkbox of find elemet or user//
        WebElement checkbox = driver.findElement(By.id("jqg_tblMainTable_243"));
        checkbox.click();

        // After checked the checkbox it enables the edit button for edit the
        // user//
        WebElement editButton = driver.findElement(By.id("btnEdit"));
        editButton.click();

        // ------------Edit user popup--------------//

        // Verify edit popup opened or not//
        String source = driver.getPageSource();
        int a = source.indexOf("Edit User:");
        if (a > 0) {
            System.out.println("Edit user popup is displayed");
        } else {
            System.out.println("Edit user popup is not displaying");
        }

        // All the WebElement parameter is located here//

        WebElement euUserName = driver.findElement(By.id("UserName"));
        euUserName.clear();
        euUserName.sendKeys("pra1");
        WebElement euFullName = driver.findElement(By.id("txtFullName"));
        euFullName.clear();
        euFullName.sendKeys("pra1");
        WebElement euPassword = driver.findElement(By.id("txtPassword"));
        euPassword.sendKeys("123456");
        WebElement euConfirmPassword = driver.findElement(By
                .id("txtConfirmPassword"));
        euConfirmPassword.sendKeys("123456");

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            System.out.println("Error in wait");
        }

        WebElement dropdown = driver.findElement(By.id("RoleID"));

        // Verify dropdown is displayed or not not //

        if (dropdown.findElement(By.id("RoleID")) != null) {
            System.out.println("Dropdown is displayed");
        } else {
            System.out.println("Dropdown is not displaying");
        }
        Select clickThis = new Select(dropdown);
        clickThis.selectByVisibleText("Normal");

        System.out.println("Drop down values "+clickThis.getOptions().get(0).getText());


        WebElement euUserDetail = driver.findElement(By.id("UserDetails"));
        euUserDetail.clear();
        euUserDetail.sendKeys("pra1");

        WebElement euOk= driver.findElement(By.xpath("/html/body/div[3]/div[3]/div/button[1]"));
        euOk.click();

        driver.manage().timeouts().implicitlyWait(1, TimeUnit.MINUTES);
        driver.quit();
    }
}

Upvotes: 1

Views: 143

Answers (3)

Ant's
Ant's

Reputation: 13811

Just call clear() method before your calling sendKeys("your text").

This should work.

Upvotes: 3

Prabu Ananthakrishnan
Prabu Ananthakrishnan

Reputation: 4259

Just use the clear function before passing the value to the webelement

WebElement userName = driver.findElement(By.name("username"));

userName.clear();

userName.sendKeys("pra");

Same way you can use for all the elements.

Upvotes: 0

Biscuit128
Biscuit128

Reputation: 5398

ok i can't even be bothered trying to read a 7 million line long main method

1) refactor it in to separate logical methods (responsibility driven design)

2) when you have done that post us the code responsible for your issues

3) maybe look at assigning the value you want to search on to a temporary variable so you can find it again?

Upvotes: -1

Related Questions