當前位置: 首頁>>代碼示例>>Java>>正文


Java By類代碼示例

本文整理匯總了Java中org.openqa.selenium.By的典型用法代碼示例。如果您正苦於以下問題:Java By類的具體用法?Java By怎麽用?Java By使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


By類屬於org.openqa.selenium包,在下文中一共展示了By類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testBrowserName

import org.openqa.selenium.By; //導入依賴的package包/類
@Test
public void testBrowserName() {
    WebDriver driver = getDriver();
    ExamplePage page = getPage();
    WebElement element = page.findElement(By.tagName("html"));
    SeleniumConfig config = SeleniumConfig.getConfig();
    String browserName = config.getBrowserCaps().getBrowserName();
    
    assertEquals(WebDriverUtils.getBrowserName((SearchContext) driver), browserName);
    assertEquals(WebDriverUtils.getBrowserName(page), browserName);
    assertEquals(WebDriverUtils.getBrowserName(element), browserName);
    
    try {
        WebDriverUtils.getBrowserName(mock(WebDriver.class));
        fail("No exception was thrown");
    } catch (UnsupportedOperationException e) {
        assertEquals(e.getMessage(), "The specified context is unable to describe its capabilities");
    }
}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:20,代碼來源:WebDriverUtilsTest.java

示例2: getByExactRepeaterRow

import org.openqa.selenium.By; //導入依賴的package包/類
@SProperty(name = "ng-exactRepeat-row")
public By getByExactRepeaterRow(String repeaterRow) {
    String repeater = repeaterRow.split("###")[0];
    int row = Integer.valueOf(repeaterRow.split("###")[1]);
    return new ByAngularRepeaterRow(NgWebDriver.DEFAULT_ROOT_SELECTOR, repeater, true, row) {
        @Override
        public List<WebElement> findElements(SearchContext searchContext) {
            List<WebElement> elements = new ArrayList<>();
            try {
                elements.add(this.findElement(searchContext));
            } catch (Exception ex) {

            }
            return elements;
        }
    };
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:18,代碼來源:AngularFindBy.java

示例3: moveTo

import org.openqa.selenium.By; //導入依賴的package包/類
@Test(enabled = false) public void moveTo() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element1 = driver.findElement(By.name("click-me"));
    new Actions(driver).moveToElement(element1).click().perform();
    buttonMouseActions.setLength(0);
    new Actions(driver).moveToElement(element1).perform();
    AssertJUnit.assertTrue(buttonMouseActions.length() > 0);
    AssertJUnit.assertEquals("moved-", buttonMouseActions.toString());
    new Actions(driver).moveToElement(element1, 10, 10).perform();
    AssertJUnit.assertEquals("moved-moved-", buttonMouseActions.toString());
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:18,代碼來源:JavaDriverTest.java

示例4: login

import org.openqa.selenium.By; //導入依賴的package包/類
public void login() throws Throwable {
    driver = new JavaDriver();
    WebElement passField = driver.findElement(By.cssSelector("password-field"));
    AssertJUnit.assertEquals("true", passField.getAttribute("enabled"));
    passField.clear();
    AssertJUnit.assertEquals("", passField.getText());
    passField.sendKeys("password");
    WebElement button = driver.findElement(By.cssSelector("button"));
    button.click();
    driver.switchTo().window("Error Message");
    WebElement label = driver.findElement(By.cssSelector("label[text*='Invalid']"));
    AssertJUnit.assertEquals("Invalid password. Try again.", label.getText());
    WebElement button1 = driver.findElement(By.cssSelector("button"));
    button1.click();
    driver.switchTo().window("JPasswordFieldTest");
    passField.clear();
    passField.sendKeys("bugaboo", Keys.ENTER);
    driver.switchTo().window("Message");
    WebElement label2 = driver.findElement(By.cssSelector("label[text*='Success']"));
    AssertJUnit.assertEquals("Success! You typed the right password.", label2.getText());
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:22,代碼來源:JPasswordFieldTest.java

示例5: get

import org.openqa.selenium.By; //導入依賴的package包/類
/**
 * Retourne un selecteur selenium à partir d'un type et d'une valeur sous forme de String. Les différents sélecteur disponible sont.
 * <ul>
 * <li>id</li>
 * <li>name</li>
 * <li>className</li>
 * <li>xpath</li>
 * <li>css</li>
 * <li>linkText</li>
 * <li>tagName</li>
 * <li>partialLinkText</li>
 * </ul>
 * Retourne null si aucun sélecteur correspondant au type passé en paramètre n'est trouvé.
 * @param type
 * @param selector
 * @return By
 */
public static By get(String type, String selector) {
    By by = null;
    if ("id".equalsIgnoreCase(type)) {
        by = By.id(selector);
    } else if ("name".equalsIgnoreCase(type)) {
        by = By.name(selector);
    } else if ("className".equalsIgnoreCase(type)) {
        by = By.className(selector);
    } else if ("xpath".equalsIgnoreCase(type)) {
        by = By.xpath(selector);
    } else if ("css".equalsIgnoreCase(type)) {
        by = By.cssSelector(selector);
    } else if ("linkText".equalsIgnoreCase(type)) {
        by = By.linkText(selector);
    } else if ("tagName".equalsIgnoreCase(type)) {
        by = By.tagName(selector);
    } else if ("partialLinkText".equalsIgnoreCase(type)) {
        by = By.partialLinkText(selector);
    }
    return by;
}
 
開發者ID:Nonorc,項目名稱:saladium,代碼行數:39,代碼來源:BySelec.java

示例6: pressGeneratesSameEvents

import org.openqa.selenium.By; //導入依賴的package包/類
public void pressGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_PRESSED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    b.click();
    AssertJUnit.assertEquals(expected, t.getText());

    tclear();
    new Actions(driver).moveToElement(b).click().perform();
    AssertJUnit.assertEquals(expected, t.getText());

}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:41,代碼來源:NativeEventsTest.java

示例7: checkAllCheckBoxes

import org.openqa.selenium.By; //導入依賴的package包/類
@Action(object = ObjectType.BROWSER, desc = "Check all the check boxes in the context")
public void checkAllCheckBoxes() {
    try {
        List<WebElement> checkboxes = Driver.findElements(By.cssSelector("input[type=checkbox]"));
        if (checkboxes.isEmpty()) {
            Report.updateTestLog(Action, "No Checkbox present in the page", Status.WARNING);
        } else {
            for (WebElement checkbox : checkboxes) {
                if (checkbox.isDisplayed() && !checkbox.isSelected()) {
                    checkbox.click();
                }
            }
            Report.updateTestLog(Action, "All checkboxes are checked", Status.PASS);
        }
    } catch (Exception ex) {
        Report.updateTestLog(Action, "Error while checking checkboxes - " + ex, Status.FAIL);
        Logger.getLogger(CheckBox.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:20,代碼來源:CheckBox.java

示例8: usedInIntegrations

import org.openqa.selenium.By; //導入依賴的package包/類
@Then("^she can see notification about integrations \"([^\"]*)\" in which is tech extension used$")
public void usedInIntegrations(String integrations) throws Throwable {
	String[] integrationsNames = integrations.split(", ");
	
	for (String integrationName : integrationsNames) {
		modalDialogPage.getElementContainingText(By.cssSelector("strong"), integrationName).shouldBe(visible);
	}
}
 
開發者ID:syndesisio,項目名稱:syndesis-qe,代碼行數:9,代碼來源:TechnicalExtensionSteps.java

示例9: clickTopTab

import org.openqa.selenium.By; //導入依賴的package包/類
/**
 * 點擊 頂部TAB
 * 
 * @param barname
 */
public static void clickTopTab(String barname) {
	LogUtil.info("點擊 頂部TAB:" + barname);
	By parentBy = By.xpath("//android.widget.HorizontalScrollView");
	By findBy = By.name(barname);
	MobileElement element = baseOpt.scrollToView(parentBy, findBy, 2, 5);
	element.click();
}
 
開發者ID:quanqinle,項目名稱:WebAndAppUITesting,代碼行數:13,代碼來源:MainFramePage.java

示例10: presenceOfNbElementsLocatedBy

import org.openqa.selenium.By; //導入依賴的package包/類
/**
 * An expectation for checking that there is at least one element present on a web page.
 *
 * @param locator
 *            used to find the element
 * @param nb
 *            is exactly number of responses
 * @return the list of WebElements once they are located
 */
public static ExpectedCondition<List<WebElement>> presenceOfNbElementsLocatedBy(final By locator, final int nb) {
    return new ExpectedCondition<List<WebElement>>() {
        @Override
        public List<WebElement> apply(WebDriver driver) {
            final List<WebElement> elements = driver.findElements(locator);
            return elements.size() == nb ? elements : null;
        }
    };
}
 
開發者ID:NoraUi,項目名稱:NoraUi,代碼行數:19,代碼來源:Utilities.java

示例11: findTextAtRow

import org.openqa.selenium.By; //導入依賴的package包/類
private WebElement findTextAtRow(String text, List<WebElement> rows) {
    for (WebElement r : rows) {
        List<WebElement> cells = r.findElements(By.tagName("td"));
        for (WebElement cell : cells) {
            if(text.trim().equals(cell.getText().trim())){
                return r;
            }
        }
    }
    return null;
}
 
開發者ID:entelgy-brasil,項目名稱:zucchini,代碼行數:12,代碼來源:ClickStep.java

示例12: typeInElement

import org.openqa.selenium.By; //導入依賴的package包/類
/**
 * @category Set Element
 */
private void typeInElement(WebElement element, String content) {
	_action.moveToElement(element);
	switch (this.getFieldType(element)) {
	case "choice":
		List<WebElement> options = element.findElements(By.tagName("option"));
		for (int i = 0; i < options.size(); i++) {
			if (options.get(i).getText().trim().equalsIgnoreCase(content)) {
				element.click();
				options.get(i).click();
				break;
			}
		}
		break;
	default:
		_action.click();
		if(!this.getFieldValueByID(element.getAttribute("id")).equalsIgnoreCase("")) {
			//TODO - Find a faster way to do this.
			_action.sendKeys(Keys.END);
			for (int i = 0; i <this.getFieldValueByID(element.getAttribute("id")).length(); i ++) {
				_action.sendKeys(Keys.BACK_SPACE);
			}

		}
		_action.sendKeys(content);
		_action.sendKeys(Keys.TAB);
	_action.perform();
	}

}
 
開發者ID:SeanABoyer,項目名稱:ServiceNow_Selenium,代碼行數:33,代碼來源:ServiceNow.java

示例13: getEnabled

import org.openqa.selenium.By; //導入依賴的package包/類
public void getEnabled() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement button = driver.findElement(By.cssSelector("button"));
    AssertJUnit.assertEquals("Click Me!!", button.getText());
    AssertJUnit.assertEquals("true", button.getAttribute("enabled"));
    button.click();
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:14,代碼來源:JavaDriverTest.java

示例14: testByID

import org.openqa.selenium.By; //導入依賴的package包/類
@Test
public void testByID() {
    IElement element = ElementBuilders.element()
            .withName("elementByID")
            .withId("textFieldID")
            .please();
    By expected = By.id("textFieldID");

    By byElementFromFactory = byFactory.byElement(element);
    Assert.assertEquals("Результат работы IOSFactory по id некорректен", expected, byElementFromFactory);
}
 
開發者ID:alfa-laboratory,項目名稱:colibri-ui,代碼行數:12,代碼來源:TestIOSByFactory.java

示例15: findElements

import org.openqa.selenium.By; //導入依賴的package包/類
/**
 * 查找元素集合
 * 
 * @param by
 * @return
 */
public List<WebElement> findElements(By by) {
	List<WebElement> elementList = null;
	try {
		elementList = getDriver().findElements(by);
	} catch (Exception e) {
		LogUtil.error(getDriver().manage().logs() + "==>" + by.toString() + " 未找到!" + e);
		screenShot();
		AssertUtil.fail(by.toString() + " 未找到!");
	}

	return elementList;
}
 
開發者ID:quanqinle,項目名稱:WebAndAppUITesting,代碼行數:19,代碼來源:BaseOpt.java


注:本文中的org.openqa.selenium.By類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。