List of usage examples for org.openqa.selenium By tagName
public static By tagName(String tagName)
From source file:com.hotwire.test.steps.search.hotel.HotelSearchModelWebApp.java
License:Open Source License
@Override public void verifyAdultNumberLimit(int maxAdults) { HotelSearchFragment hotelSearchFragment = new HotelSearchFragment(getWebdriverInstance()); assertThat(hotelSearchFragment.hotelRoomAdults().findElements(By.tagName("li")).size() == maxAdults) .as("Hotel room menu should allow to select at most " + maxAdults + " adults").isTrue(); }
From source file:com.hotwire.test.steps.search.hotel.HotelSearchModelWebApp.java
License:Open Source License
@Override public void verifyChildrenNumberLimit(int maxChildren) { HotelSearchFragment hotelSearchFragment = new HotelSearchFragment(getWebdriverInstance()); assertThat(hotelSearchFragment.hotelRoomChildren().findElements(By.tagName("li")).size() == maxChildren + 1) .as("Hotel room menu should allow to select at most " + maxChildren + " children").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 w w.j a 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 .j a va 2 s . 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();/*ww w . j a v a 2 s . c om*/ 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.htmlhifive.pitalium.it.screenshot.partialapge.KeepBodyStyleTest.java
License:Apache License
/** * body????????????isMove??<br>/* www.j av a 2 s . c o m*/ * ???????????<br> * IE711/FireFox/Chrome/Android 2.3, 4.0, 4.4/iOS 8.1<br> * ??body???????? */ @Test public void keepBodyStyleOffset() { driver.get(BASE_URL); final String position = "absolute"; final String offsetLeft = "20px"; final String offsetTop = "30px"; // ???? StringBuilder sb = new StringBuilder(); sb.append("document.body.style.position = '"); sb.append(position); sb.append("'; document.body.style.top = '"); sb.append(offsetTop); sb.append("'; document.body.style.left = '"); sb.append(offsetLeft); sb.append("';"); System.out.println(sb.toString()); driver.executeJavaScript(sb.toString()); List<CompareTarget> targets = new ArrayList<CompareTarget>(); targets.add(new CompareTarget(ScreenArea.of(SelectorType.ID, "about"), null, true)); assertionView.assertView("CssSelector", targets); // ?body????? WebElement body = driver.findElement(By.tagName("body")); //body.getCssValue("position"); assertThat(body.getCssValue("position"), is(position)); assertThat(body.getCssValue("top"), is(offsetTop)); assertThat(body.getCssValue("left"), is(offsetLeft)); }
From source file:com.htmlhifive.pitalium.it.screenshot.partialapge.KeepBodyStyleTest.java
License:Apache License
/** * body????????????isMove??<br>//from ww w. ja v a 2 s.c o m * ???????????<br> * IE711/FireFox/Chrome/Android 2.3, 4.0, 4.4/iOS 8.1<br> * ??body???????? */ @Test public void keepBodyStyleMargin() { driver.get(BASE_URL); final String position = "absolute"; final String marginWidth = "20px"; // ???? StringBuilder sb = new StringBuilder(); sb.append("document.body.style.position = '"); sb.append(position); sb.append("'; document.body.style.margin = '"); sb.append(marginWidth); sb.append("';"); System.out.println(sb.toString()); driver.executeJavaScript(sb.toString()); List<CompareTarget> targets = new ArrayList<CompareTarget>(); targets.add(new CompareTarget(ScreenArea.of(SelectorType.ID, "about"), null, true)); assertionView.assertView("CssSelector", targets); // ?body????? WebElement body = driver.findElement(By.tagName("body")); //body.getCssValue("position"); assertThat(body.getCssValue("position"), is(position)); assertThat(body.getCssValue("margin-top"), is(String.valueOf(marginWidth))); assertThat(body.getCssValue("margin-right"), is(String.valueOf(marginWidth))); assertThat(body.getCssValue("margin-bottom"), is(String.valueOf(marginWidth))); assertThat(body.getCssValue("margin-left"), is(String.valueOf(marginWidth))); }
From source file:com.huangyunkun.jviff.parser.InputStepParserTest.java
License:Apache License
@Test public void shouldParseScript() throws Exception { Step step = parser.parse("input @input content record"); assertThat(step.getAction(), is(INPUT)); assertThat(step.getTarget(), is(By.tagName("input"))); assertThat(step.getContent(), is("content")); assertThat(step.getRecord(), is(true)); }
From source file:com.huangyunkun.jviff.parser.WaitForStepParserTest.java
License:Apache License
@Test public void shouldParseScript() throws Exception { Step step = parser.parse("waitFor @button record"); assertThat(step.getAction(), is(StepAction.WAIT_FOR)); assertThat(step.getTarget(), is(By.tagName("button"))); assertThat(step.getRecord(), is(true)); }
From source file:com.ibm.sbt.automation.core.environment.TestEnvironment.java
License:Open Source License
/** * Wait the specified interval for any popup with the specified titles to * appear/* w w w . ja va2 s .c om*/ */ public WebElement waitForPopups(final int secs, final String[] titles) { try { return (new WebDriverWait(getPageObject().getWebDriver(), secs)) .until(new ExpectedCondition<WebElement>() { @Override public WebElement apply(WebDriver webDriver) { failIfPageCrashed(webDriver); WebDriver popup = findPopup(titles); if (popup != null) { return popup.findElement(By.tagName("body")); } return null; } }); } catch (Exception e) { return null; } }