List of usage examples for org.openqa.selenium By name
public static By name(String name)
From source file:com.hp.test.framework.jelly.WaitUntilElementVisibleTag.java
@Override public void doTag(XMLOutput arg0) throws MissingAttributeException, JellyTagException { logger.info("Started Execution of WaitUntilElementVisible function"); WebDriver driver = getSelenium();//from w w w. j a v a 2 s. co m int loc = id.indexOf("="); String locator = id.substring(loc + 1); String bylocator = id.substring(0, loc); System.out.println("locator" + locator); System.out.println("id" + bylocator); switch (bylocator) { case "id": { try { System.out.println("Executing case id"); WebDriverWait wait = new WebDriverWait(driver, 300); WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(locator))); } catch (TimeoutException e) { System.out.println("TimeOut Exception" + "\n" + e.getMessage()); } break; } case "name": { try { System.out.println("Executing case name"); WebDriverWait wait = new WebDriverWait(driver, 300); WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.name(locator))); } catch (TimeoutException e) { System.out.println("TimeOut Exception" + "\n" + e.getMessage()); } break; } case "xpath": { try { System.out.println("Executing case xpath"); WebDriverWait wait = new WebDriverWait(driver, 300); WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(locator))); } catch (TimeoutException e) { System.out.println("TimeOut Exception" + "\n" + e.getMessage()); } break; } case "css": { try { System.out.println("identify element with CSS path and click"); WebDriverWait wait = new WebDriverWait(driver, 300); WebElement element = wait .until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(locator))); } catch (TimeoutException e) { System.out.println("TimeOut Exception" + "\n" + e.getMessage()); break; } } try { Thread.sleep(5000); } catch (InterruptedException e) { } logger.info("Completed Execution of WaitUntilElementClickable function"); } }
From source file:com.ibm.sbt.automation.core.environment.TestEnvironment.java
License:Open Source License
protected void handleBasicLogin(BaseTest baseTest) { String loginFormId = baseTest.getProperty(PROP_BASIC_LOGINFORMID); String usernameId = baseTest.getProperty(PROP_BASIC_USERNAMEID); String passwordId = baseTest.getProperty(PROP_BASIC_PASSWORDID); String submitId = baseTest.getProperty(PROP_BASIC_SUBMITID); String username = null;//from w w w.j a v a 2 s . c o m String password = null; if (isSmartCloud()) { username = baseTest.getProperty(PROP_OAUTH10_USERNAME); password = baseTest.getProperty(PROP_OAUTH10_PASSWORD); } else { username = baseTest.getProperty(PROP_BASIC_USERNAME); password = baseTest.getProperty(PROP_BASIC_PASSWORD); } WebElement loginForm = waitForLoginForm(loginTimeout, loginFormId, null, BasicLoginTitle, baseTest); if (baseTest.isResultsReady()) return; if (loginForm != null) { WebElement usernameEl = loginForm.findElement(By.name(usernameId)); WebElement passwordEl = loginForm.findElement(By.name(passwordId)); WebElement submitEl = loginForm.findElement(By.name(submitId)); usernameEl.sendKeys(username); passwordEl.sendKeys(password); submitEl.click(); } else { // check if page was authenticated before if (baseTest.waitForResult(0) != null) return; fail("Unable to locate basic login form"); } }
From source file:com.ibm.sbt.automation.core.environment.TestEnvironment.java
License:Open Source License
protected void handleOAuth10(BaseTest baseTest) { String loginFormId = baseTest.getProperty(PROP_OAUTH10_LOGINFORMID); String usernameId = baseTest.getProperty(PROP_OAUTH10_USERNAMEID); String passwordId = baseTest.getProperty(PROP_OAUTH10_PASSWORDID); String submitId = baseTest.getProperty(PROP_OAUTH10_SUBMITID); String username = baseTest.getProperty(PROP_OAUTH10_USERNAME); String password = baseTest.getProperty(PROP_OAUTH10_PASSWORD); WebElement loginForm = waitForLoginForm(loginTimeout, loginFormId, null, OAuth10LoginTitle, baseTest); if (baseTest.isResultsReady()) return;/*from ww w . j av a2s . c o m*/ if (loginForm != null) { WebElement continueButton = loginForm.findElement(By.id("continue")); WebElement usernameEl = loginForm.findElement(By.name(usernameId)); WebElement passwordEl = loginForm.findElement(By.name(passwordId)); WebElement submitEl = loginForm.findElements(By.id(submitId)).get(0); usernameEl.sendKeys(username); if (continueButton != null) { continueButton.click(); WebDriverWait wait = new WebDriverWait(webDriver, 10); WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(submitId))); } passwordEl.sendKeys(password); submitEl.click(); } else { fail("Unable to locate OAuth1.0 login form"); } }
From source file:com.ibm.sbt.automation.core.environment.TestEnvironment.java
License:Open Source License
/** * Wait the specified interval for the specified web element to be available *//*w w w . j a v a2s.c o m*/ public WebElement waitForElement(final String match, final int secs, final String condition) { try { return (new WebDriverWait(getPageObject().getWebDriver(), secs)) .until(new ExpectedCondition<WebElement>() { @Override public WebElement apply(WebDriver webDriver) { failIfPageCrashed(webDriver); webDriver = getPageObject(webDriver).getWebDriver(); if (condition.equalsIgnoreCase("id")) { return webDriver.findElement(By.id(match)); } else if (condition.equalsIgnoreCase("linkText")) { return webDriver.findElement(By.linkText(match)); } else if (condition.equalsIgnoreCase("tagName")) { return webDriver.findElement(By.tagName(match)); } else if (condition.equalsIgnoreCase("name")) { return webDriver.findElement(By.name(match)); } else if (condition.equalsIgnoreCase("idWithText")) { WebElement element = webDriver.findElement(By.id(match)); String text = element.getText(); if (StringUtil.isNotEmpty(text)) { return element; } String value = element.getAttribute("value"); if (StringUtil.isNotEmpty(value)) { return element; } return null; } else if (condition.equalsIgnoreCase("idWithChild")) { WebElement element = webDriver.findElement(By.id(match)); List<WebElement> children = element.findElements(By.xpath("*")); if (!children.isEmpty()) { return element; } return null; } else { return webDriver.findElement(By.name(match)); } } }); } catch (Exception e) { return null; } }
From source file:com.ibm.watson.movieapp.dialog.fvt.webui.BaseUI.java
License:Open Source License
/** * Converts a locator string with a known prefix to a By object * @param myLocator//from w w w. j a v a 2s.co m * Supported locators: * xpath - "//" * id - "id=" * css selector - "css=" * xpath - "xpath=" * linktext - "link=" * name - "name=" *linkpartialtext - "linkpartial=" * @return By object extracted from given string locator */ private static By byFromLocator(String locator) { if (locator.startsWith("//")) { return By.xpath(locator); } if (locator.startsWith("id=")) { return By.id(locator.replaceFirst("id=", "")); } if (locator.startsWith("css=")) { return By.cssSelector(locator.replaceFirst("css=", "")); } if (locator.startsWith("xpath=")) { return By.xpath(locator.replaceFirst("xpath=", "")); } if (locator.startsWith("name=")) { return By.name(locator.replaceFirst("name=", "")); } if (locator.startsWith("link=")) { return By.linkText(locator.replaceFirst("link=", "")); } if (locator.startsWith("linkpartial=")) { return By.partialLinkText(locator.replaceFirst("linkpartial=", "")); } throw new IllegalArgumentException("Locator not supported: " + locator); }
From source file:com.ipinyou.webpage.abnormalwebpage.AbnormalAdvertiserPage.java
public static void create(WebDriver driver, AbnormalAdvertiserInfo adinfo, int a) throws NoSuchElementException { driver.findElement(By.className("resource-create-btn")).click(); driver.findElement(By.id("advertiser.name")).sendKeys(adinfo.adname); driver.findElement(By.id("advertiser.registerName")).sendKeys(adinfo.registername); if (a == 1) { driver.findElement(By.id("advertiser.serviceFeeRate")).sendKeys(adinfo.servicefeerate); }// w w w .java 2 s. com // driver.findElement(By.id("advertiser.selfService1")).click(); // driver.findElement(By.id("advertiser.selfService0")).click(); Select industry = new Select(driver.findElement(By.name("advertiser.verticalTagId"))); industry.selectByVisibleText(adinfo.industrytext); WebElement websuite = driver.findElement(By.id("advertiser.website")); websuite.clear(); websuite.sendKeys(adinfo.advertiserwebsite); driver.findElement(By.id("advertiser.cellphone")).sendKeys(adinfo.cellphone); driver.findElement(By.id("advertiser.contactName")).sendKeys(adinfo.contactname); driver.findElement(By.id("advertiser.email")).sendKeys(adinfo.email); driver.findElement(By.id("advertiser.showLogo1")).click(); driver.findElement(By.id("advertiser.showLogo0")).click(); WebElement addaptitude = driver.findElement(By.id("addQualificationFiles")); addaptitude.click(); if (a == 2) { addaptitude.click(); } else { ; } //ICP Select aptitudeicp = new Select(driver.findElement(By.name("types"))); aptitudeicp.selectByValue("ICP"); driver.findElement(By.name("qualifications")).sendKeys(adinfo.path); addaptitude.click(); // Select aptitudelicense = new Select(driver .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[12]/td[2]/select"))); aptitudelicense.selectByValue("License"); WebElement chooselicense = driver .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[12]/td[2]/input")); chooselicense.sendKeys(adinfo.path); addaptitude.click(); // Select aptitudelegalid = new Select(driver .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[13]/td[2]/select"))); aptitudelegalid.selectByValue("LegalId"); WebElement chooselegalid = driver .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[13]/td[2]/input")); chooselegalid.sendKeys(adinfo.path); addaptitude.click(); // Select aptitudeproduct = new Select(driver .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[14]/td[2]/select"))); aptitudeproduct.selectByValue("Product"); WebElement chooseproduct = driver .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[14]/td[2]/input")); chooseproduct.sendKeys(adinfo.path); addaptitude.click(); // Select aptitudeother = new Select(driver .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[15]/td[2]/select"))); aptitudeother.selectByValue("Other"); WebElement chooseother = driver .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[15]/td[2]/input")); chooseother.sendKeys(adinfo.path); WebElement submit = driver.findElement(By.name("submitForm")); submit.click(); }
From source file:com.ipinyou.webpage.abnormalwebpage.AbnormalAdvertiserPageName.java
public static void create(WebDriver driver, AbnormalAdvertiserNameInfo aainfo, int a) throws NoSuchElementException { driver.findElement(By.className("resource-create-btn")).click(); driver.findElement(By.id("advertiser.name")).sendKeys(aainfo.getAdname()); driver.findElement(By.id("advertiser.registerName")).sendKeys(aainfo.getRegistername()); if (a == 1) { driver.findElement(By.id("advertiser.serviceFeeRate")).sendKeys(aainfo.getServicefeerate()); }// www. j ava2 s . co m // driver.findElement(By.id("advertiser.selfService1")).click(); // driver.findElement(By.id("advertiser.selfService0")).click(); Select industry = new Select(driver.findElement(By.name("advertiser.verticalTagId"))); industry.selectByVisibleText(aainfo.getIndustrytext()); WebElement websuite = driver.findElement(By.id("advertiser.website")); websuite.clear(); websuite.sendKeys(aainfo.getAdvertiserwebsite()); driver.findElement(By.id("advertiser.cellphone")).sendKeys(aainfo.getCellphone()); driver.findElement(By.id("advertiser.contactName")).sendKeys(aainfo.getContactname()); driver.findElement(By.id("advertiser.email")).sendKeys(aainfo.getEmail()); driver.findElement(By.id("advertiser.showLogo1")).click(); driver.findElement(By.id("advertiser.showLogo0")).click(); WebElement addaptitude = driver.findElement(By.id("addQualificationFiles")); addaptitude.click(); if (a == 2) { addaptitude.click(); } else { ; } //ICP Select aptitudeicp = new Select(driver.findElement(By.name("types"))); aptitudeicp.selectByValue("ICP"); driver.findElement(By.name("qualifications")).sendKeys(aainfo.getPath()); addaptitude.click(); /*// Select aptitudelicense = new Select(driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[12]/td[2]/select"))); aptitudelicense.selectByValue("License"); WebElement chooselicense = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[12]/td[2]/input")); // chooselicense.sendKeys(aainfo.getPath()); addaptitude.click(); // Select aptitudelegalid = new Select(driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[13]/td[2]/select"))); aptitudelegalid.selectByValue("LegalId"); WebElement chooselegalid = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[13]/td[2]/input")); chooselegalid.sendKeys(aainfo.getPath()); addaptitude.click(); // Select aptitudeproduct = new Select(driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[14]/td[2]/select"))); aptitudeproduct.selectByValue("Product"); WebElement chooseproduct = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[14]/td[2]/input")); chooseproduct.sendKeys(aainfo.getPath()); addaptitude.click(); // Select aptitudeother = new Select(driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[15]/td[2]/select"))); aptitudeother.selectByValue("Other"); WebElement chooseother = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[15]/td[2]/input")); chooseother.sendKeys(aainfo.getPath());*/ WebElement submit = driver.findElement(By.name("submitForm")); submit.click(); }
From source file:com.ipinyou.webpage.abnormalwebpage.AbnormalAdvertiserPageName.java
public static void editname(WebDriver driver, AbnormalAdvertiserNameInfo aainfo) { By by = By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[1]/td[3]/span[2]"); pubdo(driver, aainfo.getAdname1(), aainfo.getAdnamereminder(), by); pubdo(driver, aainfo.getAdname2(), "", by); driver.findElement(By.id("advertiser.name")).clear(); driver.findElement(By.id("advertiser.name")).sendKeys(aainfo.getAdname3()); driver.findElement(By.id("advertiser.registerName")).clear(); driver.findElement(By.id("advertiser.registerName")).sendKeys(aainfo.getRegistername1()); driver.findElement(By.name("submitForm")).click(); String adname = driver//from w w w . j a va2 s. c o m .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[2]/td[3]/span[2]")) .getText(); if (!adname.equals("264")) { ScreenshotandAssert.screenandasserttext(driver, "", "264", By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[1]/td[3]/span[2]")); } }
From source file:com.ipinyou.webpage.abnormalwebpage.AbnormalAdvertiserPageName.java
public static void pubdo(WebDriver driver, String args, String argsreminder, By by) { driver.findElement(By.id("advertiser.name")).clear(); driver.findElement(By.id("advertiser.name")).sendKeys(args); driver.findElement(By.name("submitForm")).click(); String adname = driver.findElement(by).getText(); if (!adname.equals(argsreminder) && !"".equals(adname)) { ScreenshotandAssert.screenandasserttext(driver, "", argsreminder, by); } else if ("".equals(adname)) { ScreenshotandAssert.screenandasserttext(driver, "", "", by); }/*from w w w . j a v a2 s . co m*/ }
From source file:com.ipinyou.webpage.AdvertiserPage.java
public static void create(WebDriver driver, AdvertiserInfo adinfo, int a) throws NoSuchElementException { driver.findElement(By.className("resource-create-btn")).click(); driver.findElement(By.id("advertiser.name")).sendKeys(adinfo.adname); driver.findElement(By.id("advertiser.registerName")).sendKeys(adinfo.registername); if (a == 1) { driver.findElement(By.id("advertiser.serviceFeeRate")).sendKeys(adinfo.servicefeerate); }// w ww .j a v a2s .c om // driver.findElement(By.id("advertiser.selfService1")).click(); // driver.findElement(By.id("advertiser.selfService0")).click(); Select industry = new Select(driver.findElement(By.name("advertiser.verticalTagId"))); industry.selectByVisibleText(adinfo.industrytext); WebElement websuite = driver.findElement(By.id("advertiser.website")); websuite.clear(); websuite.sendKeys(adinfo.advertiserwebsite); //4.0 // driver.findElement(By.id("advertiser.orgCodeNo")).sendKeys(adinfo.orgcodeno); driver.findElement(By.id("advertiser.cellphone")).sendKeys(adinfo.cellphone); driver.findElement(By.id("advertiser.contactName")).sendKeys(adinfo.contactname); driver.findElement(By.id("advertiser.type0")).click(); driver.findElement(By.id("advertiser.email")).sendKeys(adinfo.email); driver.findElement(By.id("advertiser.showLogo1")).click(); driver.findElement(By.id("advertiser.showLogo0")).click(); WebElement addaptitude = driver.findElement(By.id("addQualificationFiles")); addaptitude.click(); if (a == 2) { addaptitude.click(); addaptitude.click(); } else { ; } //ICP Select aptitudeicp = new Select(driver.findElement(By.name("types"))); aptitudeicp.selectByValue("ICP"); driver.findElement(By.name("qualifications")).sendKeys(adinfo.path); addaptitude.click(); // 3.9 Select aptitudelicense = new Select(driver .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[15]/td[2]/select"))); aptitudelicense.selectByValue("License"); WebElement chooselicense = driver .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[15]/td[2]/input")); chooselicense.sendKeys(adinfo.path); addaptitude.click(); // Select aptitudelegalid = new Select(driver .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[16]/td[2]/select"))); aptitudelegalid.selectByValue("LegalId"); WebElement chooselegalid = driver .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[16]/td[2]/input")); chooselegalid.sendKeys(adinfo.path); addaptitude.click(); // Select aptitudeproduct = new Select(driver .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[17]/td[2]/select"))); aptitudeproduct.selectByValue("Product"); WebElement chooseproduct = driver .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[17]/td[2]/input")); chooseproduct.sendKeys(adinfo.path); // addaptitude.click(); Select aptitudeother = new Select(driver .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[18]/td[2]/select"))); aptitudeother.selectByValue("Other"); WebElement chooseother = driver .findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[18]/td[2]/input")); chooseother.sendKeys(adinfo.path); // 4.0 // /*Select aptitudelicense = new Select(driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[16]/td[2]/select"))); aptitudelicense.selectByValue("License"); WebElement chooselicense = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[16]/td[2]/input")); chooselicense.sendKeys(adinfo.path); addaptitude.click(); // Select aptitudelegalid = new Select(driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[17]/td[2]/select"))); aptitudelegalid.selectByValue("LegalId"); WebElement chooselegalid = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[17]/td[2]/input")); chooselegalid.sendKeys(adinfo.path); addaptitude.click(); // Select aptitudeproduct = new Select(driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[18]/td[2]/select"))); aptitudeproduct.selectByValue("Product"); WebElement chooseproduct = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[18]/td[2]/input")); chooseproduct.sendKeys(adinfo.path); addaptitude.click(); // PubHandle.select(driver, By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[19]/td[2]/select"), ""); WebElement orgen = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[19]/td[2]/input")); orgen.sendKeys(adinfo.path); // addaptitude.click(); Select aptitudeother = new Select(driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[20]/td[2]/select"))); aptitudeother.selectByValue("Other"); WebElement chooseother = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[20]/td[2]/input")); chooseother.sendKeys(adinfo.path);*/ if (a == 2) { driver.findElement(By.id("removeQ_1")).click(); driver.findElement(By.id("removeQ_2")).click(); } else { ; } WebElement submit = driver.findElement(By.name("submitForm")); submit.click(); }