List of usage examples for org.openqa.selenium By name
public static By name(String name)
From source file:com.hotwire.selenium.tools.travelAdvisory.TravelAdvisoryUpdatesPage.java
License:Open Source License
private void setCheckBox(String name, boolean value) { final WebElement webElement = findMany(By.name(name)).get(index); new Checkbox(webElement).check(); if (value) {//from ww w . j a va 2s. co m new Checkbox(webElement).check(); } else { new Checkbox(webElement).uncheck(); } }
From source file:com.hotwire.test.steps.deals.DealsModelWebApp.java
License:Open Source License
@Override public void chooseTheFirstLinkFromAllCitiesAndVerifyLocationAndURL(String vertical) { InformationPageUS informationPageUS = new InformationPageUS(getWebdriverInstance()); ArrayList<WebElement> destinationUrls = informationPageUS.getDestinationUrlsWebElements(vertical); ArrayList<String> destinationUrlsText = informationPageUS.getDestinationUrls(vertical); String firstLocationFromAllCities = destinationUrls.get(0).getText(); destinationUrls.get(0).click();//from w w w . j a va 2 s . co m if ("car".equals(vertical)) { CarSearchFragment carSearchFragment = new CarSearchFragment(getWebdriverInstance(), By.name("searchCar")); String[] location = carSearchFragment.getStartLocation().getAttribute("value").split(","); assertThat(firstLocationFromAllCities.contains(location[0])) .as("Pre-populated location contains: " + location[0]).isTrue(); assertThat(firstLocationFromAllCities.contains(location[1])) .as("Pre-populated location contains: " + location[1]).isTrue(); } else if ("flight".equals(vertical)) { throw new UnimplementedTestException("Implement Me!"); } else if ("hotel".equals(vertical)) { HotelSearchFragment hotelSearchFragment = new HotelSearchFragment(getWebdriverInstance(), By.className("landingFareFinder")); String[] location = hotelSearchFragment.getDestCity().getAttribute("value").split(","); assertThat(firstLocationFromAllCities.contains(location[0])) .as("Pre-populated location contains: " + location[0]).isTrue(); assertThat(firstLocationFromAllCities.contains(location[1])) .as("Pre-populated location contains: " + location[1]).isTrue(); hotelSearchFragment.getDestCity().clear(); } assertThat(destinationUrlsText.get(0).split("\\?")[0].equals(getWebdriverInstance().getCurrentUrl())) .as("Current URL is correct: " + getWebdriverInstance().getCurrentUrl()).isTrue(); }
From source file:com.hotwire.test.steps.helpcenter.SalesforceHelpCenterModel.java
License:Open Source License
public void switchSFAdminCategory(String category) { //Too many sub pages, that's why without page object's. Also this method will be used only for one scenario. new WebDriverWait(getWebdriverInstance(), 2) .until(ExpectedConditions.visibilityOfElementLocated(By.name("go"))).click(); //Paste category name to xpath locator String editCategory = String.format(EDIT_CATEGORY_TEMP, category); new WebDriverWait(getWebdriverInstance(), 4) .until(ExpectedConditions.visibilityOfElementLocated(By.xpath(editCategory))).click(); new WebDriverWait(getWebdriverInstance(), 2) .until(ExpectedConditions.visibilityOfElementLocated(By.name("save"))); List<WebElement> checks = getWebdriverInstance().findElements(By.cssSelector("table.detailList input")); for (WebElement check : checks) { if (helpCenterInfo.getMode().equals(HelpCenterInfo.CONTACTS_MODE.ON)) { if (!check.isSelected()) { check.click();//from ww w. ja v a2 s . c o m } } else { if (check.isSelected()) { check.click(); } } } getWebdriverInstance().findElement(By.name("save")).click(); }
From source file:com.hotwire.test.steps.purchase.air.AirPurchaseModelWebApp.java
License:Open Source License
@Override public void payWithSavedCCard() { try {/*from w w w.j ava 2s . co m*/ Thread.sleep(5000); WebElement savedCCRadio = new AirCreditCardFragment(getWebdriverInstance()).getSavedCCRadio(); savedCCRadio.click(); getWebdriverInstance().findElement(By.cssSelector("input[name='paymentForm._NAE_cpvNumber']")).clear(); getWebdriverInstance().findElement(By.cssSelector("input[name='paymentForm._NAE_cpvNumber']")) .sendKeys("999"); getWebdriverInstance().findElement(By.name("btnPaymentInfo")).click(); } catch (InterruptedException e) { System.err.println(e.getMessage()); } }
From source file:com.hotwire.test.steps.search.air.AirSearchModelWebApp.java
License:Open Source License
@Override public void verifyDestinationFieldIsFilledProperly() { String uRL = getWebdriverInstance().getCurrentUrl(); String[] auxURL = uRL.split("destinationCity="); uRL = auxURL[1];//from www . j a v a 2 s .c om auxURL = uRL.split("&noOfTickets"); uRL = auxURL[0]; auxURL = uRL.split(","); String destCity = auxURL[0]; String destState = auxURL[1].substring(3, 11); String destinationCity = destCity.toUpperCase() + ", " + destState.toUpperCase(); assertThat(destinationCity .equals(getWebdriverInstance().findElement(By.name("destinationCity")).getAttribute("value"))) .as("Destination city field should be: [" + destinationCity + "]").isTrue(); }
From source file:com.hp.test.framework.jelly.ClickCheckboxBasedonTextLinkinTableTag.java
@Override public void doTag(XMLOutput arg0) throws MissingAttributeException, JellyTagException { logger.info("Started Execution of ClickCheckboxBasedonTextLinkinTableTag"); WebDriver driver = getSelenium();/*from w ww.ja v a 2 s . c o m*/ int loc = id.indexOf("="); String locator = id.substring(loc + 1); String bylocator = id.substring(0, loc); String findelementby = ""; switch (bylocator) { case "id": { logger.info("Executing case id"); try { WebElement table = driver.findElement(By.id(locator)); findelementby = "WebElement table = driver.findElement(By.id(" + locator + "));\n"; // Now get all the TR elements from the table List<WebElement> allRows = table.findElements(By.tagName("tr")); // And iterate over them, getting the cells for (WebElement row : allRows) { List<WebElement> cells = row.findElements(By.tagName("td")); // iterate each cell and match value for (WebElement cell : cells) { if (cell.getText().equalsIgnoreCase(value)) { System.out.println(cell.getText()); WebElement checkbox = row.findElement(By.xpath(".//td/input[@type='checkbox']")); checkbox.click(); break; } } } } catch (NoSuchElementException e) { System.out.println("Element not found" + "\n" + e.getMessage()); } } case "name": { logger.info("Executing case name"); try { WebElement table = driver.findElement(By.name(locator)); findelementby = "WebElement table = driver.findElement(By.name(" + locator + "));\n"; // Now get all the TR elements from the table List<WebElement> allRows = table.findElements(By.tagName("tr")); // And iterate over them, getting the cells for (WebElement row : allRows) { List<WebElement> cells = row.findElements(By.tagName("td")); // iterate each cell and match value for (WebElement cell : cells) { if (cell.getText().equalsIgnoreCase(value)) { System.out.println(cell.getText()); WebElement checkbox = row.findElement(By.xpath(".//td/input[@type='checkbox']")); checkbox.click(); break; } } } } catch (NoSuchElementException e) { System.out.println("Element not found" + "\n" + e.getMessage()); } } case "xpath": { logger.info("Executing case xpath"); try { WebElement table = driver.findElement(By.xpath(locator)); findelementby = "WebElement table = driver.findElement(By.xpath(" + locator + "));\n"; // Now get all the TR elements from the table List<WebElement> allRows = table.findElements(By.tagName("tr")); // And iterate over them, getting the cells for (WebElement row : allRows) { List<WebElement> cells = row.findElements(By.tagName("td")); // iterate each cell and match value for (WebElement cell : cells) { if (cell.getText().equalsIgnoreCase(value)) { System.out.println(cell.getText()); WebElement checkbox = row.findElement(By.xpath(".//td/input[@type='checkbox']")); checkbox.click(); break; } } } } catch (NoSuchElementException e) { System.out.println("Element not found" + "\n" + e.getMessage()); } } case "css": { logger.info("Executing case css"); try { WebElement table = driver.findElement(By.cssSelector(locator)); findelementby = "WebElement table = driver.findElement(By.cssSelector(" + locator + "));\n"; // Now get all the TR elements from the table List<WebElement> allRows = table.findElements(By.tagName("tr")); // And iterate over them, getting the cells for (WebElement row : allRows) { List<WebElement> cells = row.findElements(By.tagName("td")); // iterate each cell and match value for (WebElement cell : cells) { if (cell.getText().equalsIgnoreCase(value)) { System.out.println(cell.getText()); WebElement checkbox = row.findElement(By.xpath(".//td/input[@type='checkbox']")); checkbox.click(); break; } } } } catch (NoSuchElementException e) { System.out.println("Element not found" + "\n" + e.getMessage()); } } logger.info("Completed Execution of ClickCheckboxBasedonTextLinkinTableTag"); } String Command = "try { \n " + findelementby + " List<WebElement> allRows = table.findElements(By.tagName(\"tr\"));\n"; Command = Command + "for (WebElement row : allRows) {\n List<WebElement> cells = row.findElements(By.tagName(\"td\"));\n"; Command = Command + "for (WebElement cell : cells) {\n "; Command = Command + " if (cell.getText().equalsIgnoreCase(value)) {\n"; Command = Command + " System.out.println(cell.getText());\n"; Command = Command + " WebElement checkbox = row.findElement(By.xpath(\".//td/input[@type='checkbox']\"));\n"; Command = Command + " checkbox.click();\nbreak\n"; Command = Command + "}\n}\n}\n"; Command = Command + "} catch (NoSuchElementException e) { System.out.println(\"Element not found\" + e.getMessage());}"; if (GenerateperformanceTests) { try { StartBrowserTag.JunitTestcase_fw.write(Command); } catch (IOException ex) { System.out.println("Exception in Writing Junit testcase file" + "\n" + ex.getMessage()); } } }
From source file:com.hp.test.framework.jelly.ClickLinkinTableTag.java
@Override public void doTag(XMLOutput arg0) throws MissingAttributeException, JellyTagException { logger.info("Started Execution of ClickLinkinTableTag"); WebDriver driver = getSelenium();// w w w. ja v a 2s . c o m int loc = id.indexOf("="); String locator = id.substring(loc + 1); String bylocator = id.substring(0, loc); String elelocator = ""; switch (bylocator) { case "id": { logger.info("Executing case id"); try { WebElement table = driver.findElement(By.id(locator)); elelocator = "WebElement table = driver.findElement(By.id(\"" + locator + "\"));\n"; List<WebElement> links = table.findElements(By.tagName("a")); for (WebElement link : links) { // String s = link.getText(); // s=s.trim(); // System.out.println(s); if (link.getText().equalsIgnoreCase(value)) { logger.info("Executing if condition for each link"); link.click(); logger.info("Clicked the link successfully"); break; } } } catch (NoSuchElementException e) { System.out.println("Element not found" + "\n" + e.getMessage()); } } case "name": { logger.info("Executing case name"); try { WebElement table = driver.findElement(By.name(locator)); elelocator = "WebElement table = driver.findElement(By.name(\"" + locator + "\"));\n"; List<WebElement> links = table.findElements(By.tagName("a")); for (WebElement link : links) { // String s = link.getText(); // s=s.trim(); // System.out.println(s); if (link.getText().equalsIgnoreCase(value)) { logger.info("Executing if condition for each link"); link.click(); logger.info("Clicked the link successfully"); break; } } } catch (NoSuchElementException e) { System.out.println("Element not found" + "\n" + e.getMessage()); } } case "xpath": { logger.info("Executing case xpath"); try { WebElement table = driver.findElement(By.xpath(locator)); elelocator = "WebElement table = driver.findElement(By.xpath(\"" + locator + "\"));\n"; List<WebElement> links = table.findElements(By.tagName("a")); for (WebElement link : links) { // String s = link.getText(); // s=s.trim(); // System.out.println(s); if (link.getText().equalsIgnoreCase(value)) { logger.info("Executing if condition for each link"); link.click(); logger.info("Clicked the link successfully"); break; } } } catch (NoSuchElementException e) { System.out.println("Element not found" + "\n" + e.getMessage()); } } case "css": { logger.info("Executing case css"); try { WebElement table = driver.findElement(By.cssSelector(locator)); elelocator = "WebElement table = driver.findElement(By.cssSelector(\"" + locator + "\"));\n"; List<WebElement> links = table.findElements(By.tagName("a")); for (WebElement link : links) { // String s = link.getText(); // s=s.trim(); // System.out.println(s); if (link.getText().equalsIgnoreCase(value)) { logger.info("Executing if condition for each link"); link.click(); logger.info("Clicked the link successfully"); break; } } } catch (NoSuchElementException e) { System.out.println("Element not found" + e.getMessage()); } } logger.info("Completed Execution of ClickLinkinTableTag"); } String Command = "try { \n " + elelocator + " List<WebElement> links = table.findElements(By.tagName(\"a\"));\n "; Command = Command + "for (WebElement link : links) {\n if (link.getText().equalsIgnoreCase(\"" + value + "\")) { \n"; Command = Command + " link.click();\n break;\n}\n}\n"; Command = Command + "}catch (NoSuchElementException e) { System.out.println(\"Element not found\" + e.getMessage());}"; if (GenerateperformanceTests) { try { StartBrowserTag.JunitTestcase_fw.write(Command); } catch (IOException ex) { System.out.println("Exception in Writing Junit testcase file" + "\n" + ex.getMessage()); } } }
From source file:com.hp.test.framework.jelly.ClickRadioBasedonTextLinkinTableTag.java
@Override public void doTag(XMLOutput arg0) throws MissingAttributeException, JellyTagException { logger.info("Started Execution of ClickCheckboxBasedonTextLinkinTableTag"); WebDriver driver = getSelenium();// w ww. j av a2s. c o m int loc = id.indexOf("="); String locator = id.substring(loc + 1); String bylocator = id.substring(0, loc); String findelementby = ""; switch (bylocator) { case "id": { logger.info("Executing case id"); try { WebElement table = driver.findElement(By.id(locator)); findelementby = "WebElement table = driver.findElement(By.id(" + locator + "));\n"; // Now get all the TR elements from the table List<WebElement> allRows = table.findElements(By.tagName("tr")); // And iterate over them, getting the cells for (WebElement row : allRows) { List<WebElement> cells = row.findElements(By.tagName("td")); // iterate each cell and match value for (WebElement cell : cells) { if (cell.getText().equalsIgnoreCase(value)) { System.out.println(cell.getText()); WebElement radio = row.findElement(By.xpath(".//td/input[@type='radio']")); radio.click(); break; } } } } catch (NoSuchElementException e) { System.out.println("Element not found" + "\n" + e.getMessage()); } } case "name": { logger.info("Executing case name"); try { WebElement table = driver.findElement(By.name(locator)); findelementby = "WebElement table = driver.findElement(By.name(" + locator + "));\n"; // Now get all the TR elements from the table List<WebElement> allRows = table.findElements(By.tagName("tr")); // And iterate over them, getting the cells for (WebElement row : allRows) { List<WebElement> cells = row.findElements(By.tagName("td")); // iterate each cell and match value for (WebElement cell : cells) { if (cell.getText().equalsIgnoreCase(value)) { System.out.println(cell.getText()); WebElement radio = row.findElement(By.xpath(".//td/input[@type='radio']")); radio.click(); break; } } } } catch (NoSuchElementException e) { System.out.println("Element not found" + "\n" + e.getMessage()); } } case "xpath": { logger.info("Executing case xpath"); try { WebElement table = driver.findElement(By.xpath(locator)); findelementby = "WebElement table = driver.findElement(By.xpath(" + locator + "));\n"; // Now get all the TR elements from the table List<WebElement> allRows = table.findElements(By.tagName("tr")); // And iterate over them, getting the cells for (WebElement row : allRows) { List<WebElement> cells = row.findElements(By.tagName("td")); // iterate each cell and match value for (WebElement cell : cells) { if (cell.getText().equalsIgnoreCase(value)) { System.out.println(cell.getText()); WebElement radio = row.findElement(By.xpath(".//td/input[@type='radio']")); radio.click(); break; } } } } catch (NoSuchElementException e) { System.out.println("Element not found" + "\n" + e.getMessage()); } } case "css": { logger.info("Executing case css"); try { WebElement table = driver.findElement(By.cssSelector(locator)); findelementby = "WebElement table = driver.findElement(By.cssSelector(" + locator + "));\n"; // Now get all the TR elements from the table List<WebElement> allRows = table.findElements(By.tagName("tr")); // And iterate over them, getting the cells for (WebElement row : allRows) { List<WebElement> cells = row.findElements(By.tagName("td")); // iterate each cell and match value for (WebElement cell : cells) { if (cell.getText().equalsIgnoreCase(value)) { System.out.println(cell.getText()); WebElement radio = row.findElement(By.xpath(".//td/input[@type='radio']")); radio.click(); break; } } } } catch (NoSuchElementException e) { System.out.println("Element not found" + "\n" + e.getMessage()); } } logger.info("Completed Execution of ClickCheckboxBasedonTextLinkinTableTag"); } String Command = "try { \n " + findelementby + " List<WebElement> allRows = table.findElements(By.tagName(\"tr\"));\n"; Command = Command + "for (WebElement row : allRows) {\n List<WebElement> cells = row.findElements(By.tagName(\"td\"));\n"; Command = Command + "for (WebElement cell : cells) {\n "; Command = Command + " if (cell.getText().equalsIgnoreCase(value)) {\n"; Command = Command + " System.out.println(cell.getText());\n"; Command = Command + " WebElement radio = row.findElement(By.xpath(\".//td/input[@type='radio']\"));\n"; Command = Command + " radio.click();\nbreak\n"; Command = Command + "}\n}\n}\n"; Command = Command + "} catch (NoSuchElementException e) { System.out.println(\"Element not found\" + e.getMessage());}"; if (GenerateperformanceTests) { try { StartBrowserTag.JunitTestcase_fw.write(Command); } catch (IOException ex) { System.out.println("Exception in writing Junit testcase file" + "\n" + ex.getMessage()); } } }
From source file:com.hp.test.framework.jelly.GetVariabletag.java
@Override public void doTag(XMLOutput arg0) throws MissingAttributeException { logger.info("Started Execution of GetVariableTag"); WebDriver driver = getSelenium();/*from ww w. ja v a 2 s . c o m*/ int loc = id.indexOf("="); String locator = id.substring(loc + 1); String bylocator = id.substring(0, loc); switch (bylocator.toLowerCase()) { case "id": { try { logger.info("Executing case id"); name = driver.findElement(By.id(locator)).getAttribute("value"); context.setVariable(var, name); } catch (NoSuchElementException e) { System.out.println("Element not found" + "\n" + e.getMessage()); } break; } case "name": { try { logger.info("Excecuting case name"); name = driver.findElement(By.name(locator)).getAttribute("value"); context.setVariable(var, name); } catch (NoSuchElementException e) { System.out.println("Element not found" + "\n" + e.getMessage()); } break; } case "xpath": { try { logger.info("Executing case xpath"); name = driver.findElement(By.xpath(locator)).getAttribute("value"); context.setVariable(var, name); } catch (NoSuchElementException e) { System.out.println("Element not found" + "\n" + e.getMessage()); } break; } case "css": { try { logger.info("Executing case css"); name = driver.findElement(By.cssSelector(locator)).getAttribute("value"); context.setVariable(var, name); } catch (NoSuchElementException e) { System.out.println("Element not found" + "\n" + e.getMessage()); } break; } } logger.info("End of Execution of GetVariableTag"); }
From source file:com.hp.test.framework.jelly.WaitUntilElementClickableTag.java
@Override public void doTag(XMLOutput arg0) throws MissingAttributeException, JellyTagException { logger.info("Started Execution of WaitUntilElementClickable function"); WebDriver driver = getSelenium();/*from w ww .j a v a2s. c om*/ 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.elementToBeClickable(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.elementToBeClickable(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.elementToBeClickable(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.elementToBeClickable(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"); } }