本文整理汇总了Java中org.openqa.selenium.By.id方法的典型用法代码示例。如果您正苦于以下问题:Java By.id方法的具体用法?Java By.id怎么用?Java By.id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openqa.selenium.By
的用法示例。
在下文中一共展示了By.id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: determineLocator
import org.openqa.selenium.By; //导入方法依赖的package包/类
/**
* Determine locator.
*
* @param locator the locator
* @return the by
*/
public By determineLocator(String locator) {
if (locator.startsWith(XPATH)) {
return By.xpath(findLocatorSubstring(locator));
} else if (locator.startsWith("//")) {
return By.xpath(locator);
} else if (locator.startsWith(NAME)) {
return By.name(findLocatorSubstring(locator));
} else if (locator.startsWith(LINK)) {
return By.linkText(findLocatorSubstring(locator));
} else if (locator.startsWith(ID)) {
return By.id(findLocatorSubstring(locator));
} else {
return By.id(locator);
}
}
示例2: 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;
}
示例3: parseElement
import org.openqa.selenium.By; //导入方法依赖的package包/类
/**
* 根据By的类型和值,返回By
*
* @author quanqinle
* @param byType 支持:id、name、xpath。其中,android id自带解混淆的功能
* @param byValue
* @return
*/
private By parseElement(String byType, String byValue) {
String lowerByType = byType.toLowerCase();
if (lowerByType.equals("id")) {
if (Constant.DRIVER_TYPE.equalsIgnoreCase("android")) {
this.by = By.id(AndroidIDUtil.getObfuscatedID(byValue));
} else {
this.by = By.id(byValue);
}
} else if (lowerByType.equals("rawid")) {
this.by = By.id(byValue);
} else if (lowerByType.equals("name")) {
this.by = By.name(byValue);
} else if (lowerByType.equals("xpath")) {
this.by = By.xpath(byValue);
} else {
this.by = By.id(byValue);
}
return by;
}
示例4: getByLocator
import org.openqa.selenium.By; //导入方法依赖的package包/类
@Override
public By getByLocator() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
By byLocator = null;
// Class<By> cls = (Class<By>) Class.forName("org.openqa.selenium.By");
// Method m = cls.getMethod(this.typeOfLocator, String[].class);
// String[] params = {this.attributeValue};
if(this.typeOfLocator.equals("id")){
byLocator = By.id(this.attributeValue);
}else if(this.typeOfLocator.equals("css")){
byLocator = By.cssSelector(this.attributeValue);
}
// return (By) m.invoke(null, (Object) params);
return byLocator;
}
示例5: 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);
}
示例6: DefaultComment
import org.openqa.selenium.By; //导入方法依赖的package包/类
public DefaultComment(WebDriver webDriver, String text, String number, Boolean active) {
this.webDriver = webDriver;
textField = new DefaultField(webDriver, By.id("Text"));
numberField = new DefaultField(webDriver, By.id("Number"));
activeChekBox = new SmartCheckBox(new DefaultCheckBox(webDriver, By.id("Active")));
saveComment = new DefaultButton(webDriver, By.cssSelector("input[value='Save']"));
allCategories = new DefaultButton(webDriver, By.name("AllSelect"));
this.text = text;
this.number = number;
this.active = active;
}
示例7: locator
import org.openqa.selenium.By; //导入方法依赖的package包/类
default By locator(String id) {
if (id.contains("//") || id.contains(".//")) {
return By.xpath(id.replace("xpath=", ""));
} else if(id.contains("css")){
return By.cssSelector(id.replace("css=", ""));
}else if(id.contains("id")) {
return By.id(id.replace("id=", ""));
}else if(id.contains("name")) {
return By.name(id.replace("name=", ""));
}else if(id.contains("link")) {
return By.linkText(id.replace("link=", ""));
}else {
throw new NotFoundException("The locator type is not found");
}
}
示例8: checkAndGetFieldType
import org.openqa.selenium.By; //导入方法依赖的package包/类
public SelenideElement checkAndGetFieldType(String elementId) {
log.info("field: {} is being checked", elementId);
By elem = By.id(elementId);
Class inputClass = getInputClass();
Class selectClass = getSelectClass();
SelenideElement element = this.getRootElement().find(elem).shouldBe(visible);
if (element.getTagName().equals("input") && isContainedInLocators(elem, inputClass) || element.getTagName().equals("select") && isContainedInLocators(elem, selectClass)) {
return element;
} else {
return null;
}
}
示例9: getLocator
import org.openqa.selenium.By; //导入方法依赖的package包/类
/**
* This method read a application descriptor file and return a {@link org.openqa.selenium.By} object (xpath, id, link ...).
*
* @param applicationKey
* Name of application. Each application has its fair description file.
* @param code
* Name of element on the web Page.
* @param args
* list of description (xpath, id, link ...) for code.
* @return a {@link org.openqa.selenium.By} object (xpath, id, link ...)
*/
public static By getLocator(String applicationKey, String code, Object... args) {
By locator = null;
logger.debug("getLocator with this application key : {}", applicationKey);
logger.debug("getLocator with this locator file : {}", Context.iniFiles.get(applicationKey));
final Ini ini = Context.iniFiles.get(applicationKey);
final Map<String, String> section = ini.get(code);
if (section != null) {
final Entry<String, String> entry = section.entrySet().iterator().next();
final String selector = String.format(entry.getValue(), args);
if ("css".equals(entry.getKey())) {
locator = By.cssSelector(selector);
} else if ("link".equals(entry.getKey())) {
locator = By.linkText(selector);
} else if ("id".equals(entry.getKey())) {
locator = By.id(selector);
} else if ("name".equals(entry.getKey())) {
locator = By.name(selector);
} else if ("xpath".equals(entry.getKey())) {
locator = By.xpath(selector);
} else if ("class".equals(entry.getKey())) {
locator = By.className(selector);
} else {
Assert.fail(entry.getKey() + " NOT implemented!");
}
} else {
Assert.fail(code + " NOT implemented in ini file " + Context.iniFiles.get(applicationKey) + "!");
}
return locator;
}
示例10: getExpectedCondition
import org.openqa.selenium.By; //导入方法依赖的package包/类
private By getExpectedCondition(final String selectorType, final String selector) {
switch (selectorType) {
case BY_XPATH:
return By.xpath(selector);
case BY_CSS:
return By.cssSelector(selector);
case BY_ID:
return By.id(selector);
case BY_LINK_TEXT:
return By.linkText(selector);
}
return By.xpath(selector);
}
示例11: readLocatorArgument
import org.openqa.selenium.By; //导入方法依赖的package包/类
protected By readLocatorArgument(String argName) {
Object argumentValue = readArgument(argName);
if (argumentValue instanceof String) {
Map<String, Object> newArgValue = new HashMap<String, Object>();
newArgValue.put("xpath", argumentValue);
argumentValue = newArgValue;
}
Map<String, Object> argValueAsMap = (Map<String, Object>) argumentValue;
if (argValueAsMap.containsKey("xpath")) {
if (argValueAsMap.get("xpath").toString().contains("''")) {
return By.xpath(argValueAsMap.get("xpath").toString().replace("''", "'"));
} else {
return By.xpath(argValueAsMap.get("xpath").toString());
}
} else if (argValueAsMap.containsKey("id")) {
return By.id(argValueAsMap.get("id").toString());
} else if (argValueAsMap.containsKey("name")) {
return By.name(argValueAsMap.get("name").toString());
} else {
throw new RuntimeException("Provide at least 1 identifier for the object by populating at least 1 of the following properties: xpath, id, name.");
}
}
示例12: ClickSubopcionMenuHover
import org.openqa.selenium.By; //导入方法依赖的package包/类
static public void ClickSubopcionMenuHover(WebDriver driver, String submenu, String opcionclick) {
// Pasamos el raton por el submenu de Gestion de alumnos para
// que aparezca el menu desplegable
Actions builder = new Actions(driver);
WebElement hoverElement = driver.findElement(By.id(submenu));
builder.moveToElement(hoverElement).perform();
// Pinchamos la opcion opcionclick
By locator = By.id(opcionclick);
driver.findElement(locator).click();
}
示例13: clickSubopcionMenuHover
import org.openqa.selenium.By; //导入方法依赖的package包/类
static public void clickSubopcionMenuHover(WebDriver driver, String submenu, String opcionclick)
{
//Pasamos el raton por el submenu de Gestion de alumnos para
//que aparezca el menu desplegable
Actions builder = new Actions(driver);
WebElement hoverElement = driver.findElement(By.id(submenu));
builder.moveToElement(hoverElement).perform();
//Pinchamos la opcion opcionclick
By locator = By.id(opcionclick);
driver.findElement(locator).click();
}
示例14: parseBy
import org.openqa.selenium.By; //导入方法依赖的package包/类
public static By parseBy(String identity) {
if (isXPath(identity)) {
return By.xpath(identity);
} else if (isCss(identity)) {
return By.cssSelector(identity);
} else {
return By.id(identity);
}
}
示例15: onTest
import org.openqa.selenium.By; //导入方法依赖的package包/类
@Test
public void onTest() {
final WebDriver webDriver = Mockito.mock(WebDriver.class);
final WebElement webElement = Mockito.mock(WebElement.class);
final Type type = new Type(webDriver, "text", () -> {});
final By byId = By.id("id");
Mockito.when(webDriver.findElement(byId)).thenReturn(webElement);
type.on(byId);
Mockito.verify(webElement).sendKeys("text");
}