如何从列表中选择特定的动态项目

时间:2015-02-13 03:10:30

标签: selenium selenium-webdriver

这是我的情景:

  1. 创建一个ID。 (ID有一个时间戳,用于回归测试)。例如abc_201502125566781。换句话说,每次都会创建一个唯一的ID。
  2. 转到另一个屏幕,在下拉菜单中选择在步骤1中创建的相同ID。(手动测试确认ID在步骤1的下拉菜单中可用)
  3. 以下代码有效(不是真的),因为它在搜索字段中创建新的id,并抓取它,而不是上面步骤1中的id。如何告诉驱动程序获取在步骤1中创建的ID。谢谢!

    注意:domain_id已为其分配了时间戳。

    public static String domain_id = PropertyLoader.loadProperty("PVT_DOMAIN_ID") + now;
    

    我的代码:

    WebDriverWait wait = new WebDriverWait(driver, 60);
    
    By xpath = By.xpath("//div[@id='overview_form']//select/option");
    WebElement element = new WebDriverWait(driver,10).until(ExpectedConditions.presenceOfElementLocated(xpath));
    
    element = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//option[.='" + domain_id + "']"))); 
    
    String getThePreviouslyCreatedsiteId = element.getText().trim();
    
    driver.findElement(By.xpath(PvtConstants.ADD_PAGE_SITES_PULLDOWN_SEARCH_FIELD)).sendKeys(getThePreviouslyCreatedsiteId);
    driver.findElement(By.xpath(PvtConstants.ADD_PAGE_SITES_PULLDOWN_SEARCH_FIELD)).sendKeys(Keys.ENTER);
    

    第1步:

    /*1. From Left Navigation bar, select Setup > Sites*/
    setup.setUp();
    siteClickFromLeftHandMenu();
    
    /*2. Click the +Add button*/
    clickToAddNewSiteButton();
    
    
    /*3. On Add/Edit Site screen, enter a valid Site ID (i.e. Site_timestamp) and click Add.*/
    driver.findElement(By.xpath(PvtConstants.ADD_SITE_ID)).sendKeys(site_id);
    verifyDisplay(site_id + "", By.xpath(PvtConstants.ADD_SITE_ID));
    
    /*4. Enter the same value as domain.*/
    driver.findElement(By.xpath(PvtConstants.ADD_SITE_DOMAIN)).sendKeys(domain_id);
    verifyDisplay(domain_id + "", By.xpath(PvtConstants.ADD_SITE_DOMAIN));
    
    driver.findElement(By.xpath(PvtConstants.ADD_SITE_DOMAIN)).getText();
    
    //click to add the site
    clickAddToAddSiteInTheAccount();
    
    
    /*5. The message "Successfully Added" is displayed.*/
    verifyDisplay("Successfully added.", By.id(PvtConstants.ADD_SITE_SUCCESSFULLY_ADDED_MESSSAGE));
    

0 个答案:

没有答案