2014-08-31 59 views
1

有一个用户名表的列表,我从这些表中编辑了用户名“Pra”到“Pra1”,但现在当我来到用户表列表中时,它找不到名为“Pra”的用户,因为它的更新与“Pra1”。 所以,我想要的是更新搜索过滤器中的用户名后,它使用更新的用户名(使用“Pra1”)进行搜索。 下面是运行的代码高达更新的用户名请帮我后:如何重置字段中的用户名称?

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(); 
    } 
} 

回答

-1

好,我甚至不能被人打扰试图读取700万线长的主要方法

1)重构它在分离逻辑方法(责任驱动设计)

2)当你做到这一点后我们负责的代码为您的问题

3)也许看分配要在搜索到一个临时变量s的值你可以再次找到它?

+0

请问您可以发表它的例子吗? – user2092132 2014-08-31 08:11:36

0

的值传递给webelement

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

userName.clear()之前只需使用清除功能;

userName.sendKeys("pra"); 

您可以使用所有元素的相同方法。

3

在您致电sendKeys("your text")之前,请致电clear()方法。

这应该工作。

+0

如果有效,你可以接受答案:) – 2014-09-01 09:09:32

相关问题