当前位置: 首页>>代码示例>>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;未经允许,请勿转载。