这是我的情景:
以下代码有效(不是真的),因为它在搜索字段中创建新的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));