Java Code Examples for org.openqa.selenium.By#id()

The following examples show how to use org.openqa.selenium.By#id() . 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: MultipleBrowsersTest.java    From webdrivermanager-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void test() {
    // Your test code here. For example:
    WebDriverWait wait = new WebDriverWait(driver, 30);
    driver.get("https://en.wikipedia.org/wiki/Main_Page");

    By searchInput = By.id("searchInput");
    wait.until(presenceOfElementLocated(searchInput));
    driver.findElement(searchInput).sendKeys("Software");
    By searchButton = By.id("searchButton");
    wait.until(elementToBeClickable(searchButton));
    driver.findElement(searchButton).click();

    wait.until(textToBePresentInElementLocated(By.tagName("body"),
            "Computer software"));
}
 
Example 2
Source File: ElementService.java    From senbot with MIT License 6 votes vote down vote up
public By translateLocator(String locatorString) {
	By locator = null;
	String lowerCaseLocatorString = locatorString.toLowerCase();
	if (lowerCaseLocatorString.startsWith(XPATH_LOCATOR_PREFIX)) {
		locator = By.xpath(locatorString.replace(XPATH_LOCATOR_PREFIX, ""));
	} else if (lowerCaseLocatorString.startsWith(ID_LOCATOR_PREFIX)) {
		locator = By.id(locatorString.replace(ID_LOCATOR_PREFIX, ""));
	} else if (lowerCaseLocatorString.startsWith(NAME_ATTRIBUTE_LOCATOR_PREFIX)) {
		locator = By.xpath("//*[@name='" + locatorString.replace(NAME_ATTRIBUTE_LOCATOR_PREFIX, "") + "']");
	} else if (lowerCaseLocatorString.startsWith(CSS_LOCATOR_PREFIX)) {
		locator = By.cssSelector(locatorString.replace(CSS_LOCATOR_PREFIX, ""));
	} else {
		locator = getReferenceService().getElementLocatorForElementReference(locatorString);
	}
	return locator;
}
 
Example 3
Source File: MDMHomePage.java    From product-emm with Apache License 2.0 6 votes vote down vote up
/**
 * Imitate change password action.
 *
 * @param user            current logged in user's username.
 * @param currentPassword current password.
 * @param newPassword     changed password.
 * @throws InterruptedException
 */
public void changePassword(String user, String currentPassword, String newPassword) throws InterruptedException {
    driver.findElement(By.xpath(uiElementMapper.getElement("emm.home.navbar.logged.in.user.span"))).click();
    driver.findElement(By.id(uiElementMapper.getElement("emm.home.change.password.button.id"))).click();

    CommonUtil.setValueOfHiddenInput(driver, uiElementMapper.getElement("emm.home.user.input.id"), user);
    By currentPasswordInput = By.id(uiElementMapper.getElement("emm.home.change.password.current.pwd.input"));
    wait.until(ExpectedConditions.visibilityOfElementLocated(currentPasswordInput));
    WebElement inputElement = driver.findElement(currentPasswordInput);
    inputElement.sendKeys(currentPassword);
    inputElement = driver.findElement(By.id(uiElementMapper.getElement("emm.home.change.password.new.pwd.input")));
    inputElement.sendKeys(newPassword);
    inputElement = driver
            .findElement(By.id(uiElementMapper.getElement("emm.home.change.password.retype.pwd.input")));
    inputElement.sendKeys(newPassword);
    driver.findElement(By.id(uiElementMapper.getElement("emm.home.change.password.yes.link.id"))).click();
    CommonUtil.waitAndClick(driver, By.id(uiElementMapper.getElement("emm.home.change.password.success.link")));
}
 
Example 4
Source File: InstructorCopyFsToModal.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
public void waitForModalToLoad() {
    By byCopiedFsNameField = By.id(Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME);
    waitForElementPresence(byCopiedFsNameField);
    waitForElementVisibility(browser.driver.findElement(byCopiedFsNameField));

    copyModalStatusMessage = browser.driver.findElement(By.id(FEEDBACK_COPY_MODAL_STATUS));
}
 
Example 5
Source File: InstructorCoursesPage.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
public void waitForAjaxLoadCoursesError() {
    By element = By.id("retryAjax");
    waitForElementPresence(element);
    WebElement statusMessage =
            browser.driver.findElement(By.id("statusMessagesToUser")).findElement(By.className("statusMessage"));
    assertEquals("Courses could not be loaded. Click here to retry.", statusMessage.getText());
}
 
Example 6
Source File: SeleniumApplicationTest.java    From bootiful-testing-online-training with Apache License 2.0 5 votes vote down vote up
@Test
public void navigate() {
	driver.get("http://localhost:8080/p1.php");
	Page1 pg1 = PageFactory.initElements(driver, Page1.class);
	Assert.assertEquals(pg1.title(), "Page 1");
	By id = By.id("p2-link");
	WebElement element = this.driver.findElement(id);
	Assert.assertEquals(element.getText(), "Go To Page 2");
	element.click();

	Page2 pg2 = PageFactory.initElements(driver, Page2.class);
	WebElement message = pg2.message();
	Assert.assertEquals(message.getText(), "Welcome!");
}
 
Example 7
Source File: AdminHomePage.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
public String getMessageForInstructor(int i) {
    By by = By.id("message-instructor-" + i);
    waitForElementVisibility(by);
    WebElement element = browser.driver.findElement(by);
    if (element == null) {
        return null;
    }
    return element.getText();
}
 
Example 8
Source File: BaseAction.java    From PatatiumWebUi with Apache License 2.0 5 votes vote down vote up
static By getBy (ByType byType,Locator locator)
{
	switch(byType)
	{
		case id:
			return By.id(locator.getElement());
		case cssSelector:
			return By.cssSelector(locator.getElement());
		case name:
			return By.name(locator.getElement());
		case xpath:
			return By.xpath(locator.getElement());
		case className:
			return By.className(locator.getElement());
		case tagName:
			return By.tagName(locator.getElement());
		case linkText:
			return By.linkText(locator.getElement());
		case partialLinkText:
			return By.partialLinkText(locator.getElement());
		//return null也可以放到switch外面
		default:
			return null;
	}


}
 
Example 9
Source File: AbstractFindByBuilder.java    From selenium with Apache License 2.0 5 votes vote down vote up
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 10
Source File: PerformanceChromeTest.java    From webdrivermanager-examples with Apache License 2.0 5 votes vote down vote up
private void singleTestExcution(WebDriver driver) {
    WebDriverWait wait = new WebDriverWait(driver, 30);
    driver.get("https://en.wikipedia.org/wiki/Main_Page");

    By searchInput = By.id("searchInput");
    wait.until(presenceOfElementLocated(searchInput));
    driver.findElement(searchInput).sendKeys("Software");
    By searchButton = By.id("searchButton");
    wait.until(elementToBeClickable(searchButton));
    driver.findElement(searchButton).click();

    wait.until(textToBePresentInElementLocated(By.tagName("body"),
            "Computer software"));
}
 
Example 11
Source File: InstructorHomePage.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
public void clickFsCopyButton(String courseId, String feedbackSessionName) {
    By fsCopyButtonElement = By.id("button_fscopy" + "-" + courseId + "-" + feedbackSessionName);

    // give it some time to load as it is loaded via AJAX
    waitForElementPresence(fsCopyButtonElement);

    WebElement fsCopyButton = browser.driver.findElement(fsCopyButtonElement);
    fsCopyButton.click();
}
 
Example 12
Source File: DoesNotRecordClickingOnLinksIT.java    From bromium with MIT License 5 votes vote down vote up
@Override
public void run(RecordingSimulatorModule recordingSimulatorModule) {
    String baseUrl = (String) opts.get(URL);
    WebDriver webDriver = recordingSimulatorModule.getWebDriver();
    WebDriverWait webDriverWait = new WebDriverWait(webDriver, 10);
    webDriver.get(baseUrl + "index.html");
    By byId = By.id(AJAX_DEMO_LINK);
    webDriverWait.until(ExpectedConditions.presenceOfElementLocated(byId));
    webDriver.findElement(byId).click();
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        logger.error(e.getMessage(), e);
    }
}
 
Example 13
Source File: InstructorCoursesPage.java    From teammates with GNU General Public License v2.0 4 votes vote down vote up
private WebElement getDeleteButtonInRow(int rowId) {
    By deleteButton = By.id("btn-delete-" + rowId);
    return browser.driver.findElement(deleteButton);
}
 
Example 14
Source File: InstructorFeedbackEditPage.java    From teammates with GNU General Public License v2.0 4 votes vote down vote up
private By getVisibilityMessageBy(int questionNumber) {
    return By.id("visibilityMessage-" + questionNumber);
}
 
Example 15
Source File: InstructorCoursesPage.java    From teammates with GNU General Public License v2.0 4 votes vote down vote up
private WebElement getUnarchiveButtonInRow(int rowId) {
    By archiveButton = By.id("btn-unarchive-" + rowId);
    return browser.driver.findElement(archiveButton);
}
 
Example 16
Source File: CartMenuForm.java    From aquality-selenium-java with Apache License 2.0 4 votes vote down vote up
public CartMenuForm() {
    super(By.id("button_order_cart"), "Cart Menu");
}
 
Example 17
Source File: AssistantFindPanel.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
public void waitForm() {
  By findPanelLocator = By.id(PANEL_ID);
  seleniumWebDriverHelper.waitVisibility(findPanelLocator);
  testWebElementRenderChecker.waitElementIsRendered(findPanelLocator);
}
 
Example 18
Source File: DefaultFindBy.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 4 votes vote down vote up
@SProperty(name = "id")
public By getById(String id) {
    return By.id(id);
}
 
Example 19
Source File: InstructorCoursesPage.java    From teammates with GNU General Public License v2.0 4 votes vote down vote up
private int getCourseCount() {
    By activeCoursesTable = By.id("tableActiveCourses");
    waitForElementPresence(activeCoursesTable);
    return browser.driver.findElement(activeCoursesTable).findElements(By.tagName("tr")).size();
}
 
Example 20
Source File: InstructorCoursesPage.java    From teammates with GNU General Public License v2.0 4 votes vote down vote up
private WebElement getMoveToRecycleBinButtonInRow(int rowId) {
    By moveToRecycleBinButton = By.id("btn-soft-delete-" + rowId);
    return browser.driver.findElement(moveToRecycleBinButton);
}