Java Code Examples for org.openqa.selenium.By#className()
The following examples show how to use
org.openqa.selenium.By#className() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PropertyFileObjectRepositoryManager.java From qashowcase with GNU General Public License v3.0 | 6 votes |
/** * Gets the By locator through reading the object repository. * @param key Is in the form of HomePage.LoginLink or ${pageName}.${elementName} * @return A By locator that can be used to locate WebElement(s). */ public By getByFromObjectRepositoryLocator(String key) { By by = null; String locatorType = getLocatorTypeString(key); String locatorString = getLocatorValueString(key); if(locatorType != null && locatorString != null) { if(locatorType.equalsIgnoreCase("LINK_TEXT")) { by = By.linkText(locatorString); } else if (locatorType.equalsIgnoreCase("PARTIAL_LINK_TEXT")) { by = By.partialLinkText(locatorString); } else if (locatorType.equalsIgnoreCase("NAME")) { by = By.name(locatorString); } else if (locatorType.equalsIgnoreCase("ID")) { by = By.id(locatorString); } else if (locatorType.equalsIgnoreCase("CLASS_NAME")) { by = By.className(locatorString); } else if (locatorType.equalsIgnoreCase("TAG_NAME")) { by = By.tagName(locatorString); } else if (locatorType.equalsIgnoreCase("CSS_SELECTOR")) { by = By.cssSelector(locatorString); } else if (locatorType.equalsIgnoreCase("XPATH")) { by = By.xpath(locatorString); } } return by; }
Example 2
Source File: ClickClassByTextTest.java From bromium with MIT License | 6 votes |
@Test public void throwsExceptionIfNoSuitableElementsAreFound() { WebElement incorrectWebElement = mock(WebElement.class); when(incorrectWebElement.getText()).thenReturn("sometATPhing"); when(incorrectWebElement.isDisplayed()).thenReturn(true); List<WebElement> webElements = new ArrayList<>(); webElements.add(incorrectWebElement); By elementsLocator = By.className(initialCollectorClass); WebDriver webDriver = mock(WebDriver.class); when(webDriver.findElements(elementsLocator)).thenReturn(webElements); SearchContextFunction contextProvider = webDriver1 -> webDriver; ClickClassByText clickClassByText = new ClickClassByText(initialCollectorClass, text, expectsHttp, contextProvider); thrown.expect(ElementNotSelectableException.class); clickClassByText.executeAfterJSPreconditionHasBeenSatisfied(webDriver, mock(ReplayingState.class), contextProvider); }
Example 3
Source File: ClickClassByText.java From bromium with MIT License | 6 votes |
@Override public void executeAfterJSPreconditionHasBeenSatisfied(WebDriver driver, ReplayingState state, Function<SearchContext, SearchContext> contextProvider) { By elementsLocator = By.className(initialCollectorClass); List<WebElement> webElements = contextProvider.apply(driver).findElements(elementsLocator); Optional<WebElement> webElementOptional = webElements.stream() .filter(this::elementTextIsEqualToAndIsDisplayed) .findFirst(); if (!webElementOptional.isPresent()) { throw new ElementNotSelectableException("Element with class " + initialCollectorClass + " and text " + text + " was not found" ); } webElementOptional.get().click(); }
Example 4
Source File: StepDefinitions.java From demo-java with MIT License | 5 votes |
@When("^I add (\\d+) items? to the cart$") public void add_items_to_cart(int items){ By itemButton = By.className("btn_primary"); IntStream.range(0, items).forEach(i -> { wait.until(ExpectedConditions.elementToBeClickable(getDriver().findElement(itemButton))); getDriver().findElement(itemButton).click(); }); }
Example 5
Source File: ClickClassByTextTest.java From bromium with MIT License | 5 votes |
@Test public void throwsExceptionIfNoElementsAreFound() { List<WebElement> webElements = new ArrayList<>(); By elementsLocator = By.className(initialCollectorClass); WebDriver webDriver = mock(WebDriver.class); when(webDriver.findElements(elementsLocator)).thenReturn(webElements); SearchContextFunction contextProvider = webDriver1 -> webDriver; ClickClassByText clickClassByText = new ClickClassByText(initialCollectorClass, text, expectsHttp, contextProvider); thrown.expect(ElementNotSelectableException.class); clickClassByText.executeAfterJSPreconditionHasBeenSatisfied(webDriver, mock(ReplayingState.class), contextProvider); }
Example 6
Source File: WebDriverService.java From cerberus-source with GNU General Public License v3.0 | 5 votes |
private By getBy(Identifier identifier) { LOG.debug("Finding selenium Element : " + identifier.getLocator() + " by : " + identifier.getIdentifier()); if (identifier.getIdentifier().equalsIgnoreCase("id")) { return By.id(identifier.getLocator()); } else if (identifier.getIdentifier().equalsIgnoreCase("name")) { return By.name(identifier.getLocator()); } else if (identifier.getIdentifier().equalsIgnoreCase("class")) { return By.className(identifier.getLocator()); } else if (identifier.getIdentifier().equalsIgnoreCase("css")) { return By.cssSelector(identifier.getLocator()); } else if (identifier.getIdentifier().equalsIgnoreCase("xpath")) { return By.xpath(identifier.getLocator()); } else if (identifier.getIdentifier().equalsIgnoreCase("link")) { return By.linkText(identifier.getLocator()); } else if (identifier.getIdentifier().equalsIgnoreCase("data-cerberus")) { return By.xpath("//*[@data-cerberus='" + identifier.getLocator() + "']"); } else { throw new NoSuchElementException(identifier.getIdentifier()); } }
Example 7
Source File: AbstractFindByBuilder.java From selenium with Apache License 2.0 | 5 votes |
protected By buildByFromShortFindBy(FindBy findBy) { if (!"".equals(findBy.className())) { return By.className(findBy.className()); } if (!"".equals(findBy.css())) { return By.cssSelector(findBy.css()); } if (!"".equals(findBy.id())) { return By.id(findBy.id()); } if (!"".equals(findBy.linkText())) { return By.linkText(findBy.linkText()); } if (!"".equals(findBy.name())) { return By.name(findBy.name()); } if (!"".equals(findBy.partialLinkText())) { return By.partialLinkText(findBy.partialLinkText()); } if (!"".equals(findBy.tagName())) { return By.tagName(findBy.tagName()); } if (!"".equals(findBy.xpath())) { return By.xpath(findBy.xpath()); } // Fall through return null; }
Example 8
Source File: Locators.java From functional-tests-core with Apache License 2.0 | 4 votes |
public By frameLayoutLocator() { return By.className(this.uiElementClass.frameLayoutLocator()); }
Example 9
Source File: Locators.java From functional-tests-core with Apache License 2.0 | 4 votes |
public By imageButtonLocator() { return By.className(this.uiElementClass.imageButtonLocator()); }
Example 10
Source File: Locators.java From functional-tests-core with Apache License 2.0 | 4 votes |
public By imageLocator() { return By.className(this.uiElementClass.imageLocator()); }
Example 11
Source File: InstructorFeedbackEditPage.java From teammates with GNU General Public License v2.0 | 4 votes |
private String getDatepickerMonth() { By by = By.className("ui-datepicker-month"); waitForElementPresence(by); return browser.driver.findElement(by).getText(); }
Example 12
Source File: Locators.java From functional-tests-core with Apache License 2.0 | 4 votes |
public By textViewLocator() { return By.className(this.uiElementClass.textViewLocator()); }
Example 13
Source File: Locators.java From functional-tests-core with Apache License 2.0 | 4 votes |
public By tabWidgetLocator() { return By.className(this.uiElementClass.tabWidgetLocator()); }
Example 14
Source File: Locators.java From functional-tests-core with Apache License 2.0 | 4 votes |
public By buttonLocator() { return By.className(this.uiElementClass.buttonLocator()); }
Example 15
Source File: Locators.java From functional-tests-core with Apache License 2.0 | 4 votes |
public By tabHostLocator() { return By.className(this.uiElementClass.tabHostLocator()); }
Example 16
Source File: ProductTabContentForm.java From aquality-selenium-java with Apache License 2.0 | 4 votes |
public ProductTabContentForm() { super(By.className("tab-content"), "Product tab content"); }
Example 17
Source File: Locators.java From functional-tests-core with Apache License 2.0 | 4 votes |
public By webViewLocator() { return By.className(this.uiElementClass.webViewLocator()); }
Example 18
Source File: Locators.java From functional-tests-core with Apache License 2.0 | 4 votes |
public By navigationBarLocator() { return By.className(this.uiElementClass.navigationBarLocator()); }
Example 19
Source File: SeleniumCssLocator.java From phoenix.webui.framework with Apache License 2.0 | 4 votes |
@Override public By getBy() { return By.className(getValue()); }
Example 20
Source File: Locators.java From functional-tests-core with Apache License 2.0 | 4 votes |
public By switchLocator() { return By.className(this.uiElementClass.switchLocator()); }