2015-02-07 28 views
1

我正在創建新用戶的場景。因爲,我將爲迴歸創建大量新用戶,我將分配一個時間戳來區分每個用戶標識。例如,ABC_2015020615215,ABC_2015020615222等 創建和發送用戶與時間戳代碼:如何獲取舊ID並插入新文本字段

public static String now = "_" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); 

// user 
public static String user_id = PropertyLoader.loadProperty("USER_ID") + now; 

下一個場景:我要抓住最後一個用戶加入,並插入一個新的文本字段,在不同的頁面上。 (保持在同一個驅動程序會話中)。

這段代碼創建一個新用戶:

//enter user id in the text field and add a new user 
driver.findElement(By.name(PvtConstants.ADD_USER_ID_TEXT_FIELD)).sendKeys(user_id); 

這是一個新的文本字段,在這裏我需要插入在上一步中添加用戶。我無法弄清楚。先謝謝您的幫助!

driver.findElement(By.id(PvtConstants.READ_USER_ADVANCED_FILTER_USER_SEARCH_FIELD)); 

HTML:

<table class="table smallInput dataTable" id="dataTableAdvertisers" "> 
<thead> 
<tr role="row" style="height: 0px;"> 
<th class="sorting_asc" tabindex="0" "></th> 
<th class="sorting" tabindex="0" "></th> 
<th class="sorting" tabindex="0" "></th> 
</tr> 
</thead> 
<tbody role="alert" aria-live="polite" aria-relevant="all"> 
    <tr class="odd"> 
    <td class=""> 
    <a href="getadvertiserdetailsNew.do?advertiserKey=198909">Advertiser_20150204130817</a></td> 
    <td class="">---</td> 
    <td class="">---</td> 
    <td class="">---</td> 
    <td class="">---</td> 
    </tr><tr class="even"> 
    <td class=""> 
    <a href="getadvertiserdetailsNew.do?advertiserKey=198910">Advertiser_20150204130923</a></td> 
    <td class="">---</td> 
    <td class="">---</td> 
    <td class="">---</td><td class="">---</td> 
    </tr><tr class="odd"> 

    </tbody> 
    </table> 
+0

當您添加用戶時會發生什麼?它會創建一個無序列表或鏈接嗎?或者是什麼? – Saifur 2015-02-07 01:21:33

+0

是的,它會創建一個表格,其中每個用戶都在。而在用戶界面中,這些用戶是可點擊的 – familyGuy 2015-02-07 01:25:32

+0

你可以提供表格的html嗎? – Saifur 2015-02-07 01:26:41

回答

1

我會用一個Xpath與傳遞user_id爲參數。 注意:此xpath匹配任何a標記與user_id變量提供的文本,在您的情況下,它是最後一個實例化的帶有時間戳的變量。

By byXpath = By.xpath("//a[.='" + user_id + "']"); 

WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(byXpath)); 
String newUser = myDynamicElement.getText().trim(); 

//send newUser this to the search field 
+0

我很抱歉,但我無法理解上面的代碼,主要是點擊部分。你想讓我點擊哪裏? – familyGuy 2015-02-07 02:21:49

+0

對不起,我感到困惑。我也誤解了你的代碼。你能解釋一下嗎?這是一個新的文本字段,我需要插入在上一步中添加的用戶「你需要插入什麼?類似於「Advertiser_20150204130923」? – Saifur 2015-02-07 02:27:13

+0

是的,我需要插入上一步添加的user_id,即Advertiser_20150204130923。所以,真正的場景是,創建一個用戶並添加它。然後轉到另一個屏幕。該頁面有一個字段,列出所有用戶標識。在頁面上有一個搜索欄。選擇搜索字段,插入與上一步中創建的相同的user_id。它應該過濾搜索並只顯示列表中的user_id ... – familyGuy 2015-02-07 02:31:16

相關問題