我的情景:如何搜索和數據輸入到搜索字段
- 創建ID
- 輸入ID進入搜索領域,這是在步驟1中創建
如果id在當前屏幕上可見/可用的id列表中(下面的屏幕截圖)可用,我可以獲取id並輸入搜索字段。但是,如果ID在當前屏幕上不可見/可用,則腳本無法檢索它。在這種情況下,我將不得不點擊右箭頭按鈕進入下一個列表,在那裏搜索該ID,然後輸入搜索字段。
我的代碼在下面的代碼中獲取id,如果它在第一個屏幕中可用的話。我曾嘗試使用if語句,但它不起作用。任何幫助是極大的讚賞!
我的腳本:
/*3. Enter the Site ID of the advertiser created in the previous step.*/
//this finds the ANY <a> tag with the text supplied by the site_id
WebElement siteId = driver.findElement(By.xpath("//a[.='" + site_id + "']"));
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//a[.='" + site_id + "']")));
if(!(driver.findElement(By.xpath(PvtConstants.READ_SITES_IDS)).getText().contains("//a[.='" + site_id + "']"))){
//click on the Right-Arrow Button
driver.findElement(By.xpath(".//*[@id='dataTableSite_wrapper']/div[3]/div[2]/span[3]")).click();
//get a text/copy of the site_id
String getThePreviouslyCreatedsiteId = siteId.getText().trim();
//insert the text into the Advanced Filters Search Field
driver.findElement(By.id(PvtConstants.READ_SITES_ADVANCED_FILTER_SITE_SEARCH_FIELD)).sendKeys(getThePreviouslyCreatedsiteId);
UI截圖:
你必須使用findElements知道Id是否存在比使用if條件。請觀看此視頻以獲取詳細說明。 https://www.youtube.com/watch?v=4xILWxRC9aA。如果你能提供你正在得到的錯誤,那將是非常好的。 – Uday 2015-02-09 04:14:59
gettext將如何包含您傳遞的xpath?在屏幕上似乎沒有任何xpath可見 – 2015-02-09 06:33:24