本文整理汇总了Java中org.openqa.selenium.By.cssSelector方法的典型用法代码示例。如果您正苦于以下问题:Java By.cssSelector方法的具体用法?Java By.cssSelector怎么用?Java By.cssSelector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openqa.selenium.By
的用法示例。
在下文中一共展示了By.cssSelector方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: countRowsTable
import org.openqa.selenium.By; //导入方法依赖的package包/类
/**
* Méthode countRowsTable. Prévoir une DIV avant la déclaration du tableau <display:table />.
* @param type
* @param selector
* @return
*/
private int countRowsTable(String type, String selector) throws TimeoutException {
int retour = 0;
try {
By locator = By.cssSelector(".pagebanner");
WebElement pagebanner = wait.until(ExpectedConditions.presenceOfElementLocated(locator));
String pageNumber = pagebanner.getText().trim().split(" ")[0];
if (!pageNumber.equals("Aucun")) {
return Integer.valueOf(pageNumber);
}
} catch (TimeoutException e) {
String pathScreenShot = takeScreenShot();
Assert.fail("countRowsTable impossible ! (type" + type + ", selector" + selector + ")"
+ e.getMessage() + " pathScreenShot=" + pathScreenShot);
}
return retour;
}
示例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: canClickIfThereAreSuitableElements
import org.openqa.selenium.By; //导入方法依赖的package包/类
@Test
public void canClickIfThereAreSuitableElements() throws Exception {
WebElement webElement = mock(WebElement.class);
String cssSelector = ".test-element";
String eventName = "CLICK_SOMETHING";
boolean expectsHttpRequest = false;
By elementLocator = By.cssSelector(cssSelector);
WebDriver webDriver = mock(WebDriver.class);
when(webDriver.findElement(elementLocator)).thenReturn(webElement);
ClickCssSelector action = new ClickCssSelector(cssSelector, eventName, expectsHttpRequest);
action.executeAfterJSPreconditionHasBeenSatisfied(webDriver, mock(ReplayingState.class));
verify(webElement).click();
assertEquals(eventName, action.getName());
assertEquals(expectsHttpRequest, action.expectsHttpRequest());
assertEquals(CLICK_CSS_SELECTOR + " " + cssSelector, action.getJSEventToWaitFor());
}
示例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: 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;
}
示例6: switchPage
import org.openqa.selenium.By; //导入方法依赖的package包/类
private void switchPage() {
Elements elements = new DefaultElements(webDriver, By.cssSelector(".webgrid-footer a"));
Iterator<Element> iterator = elements.find(new ContainsText(page));
if (iterator.hasNext()) {
new DefaultButton(iterator.next()).press();
}
}
示例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: 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;
}
示例9: testMyLocation
import org.openqa.selenium.By; //导入方法依赖的package包/类
@Test
public void testMyLocation() {
WebDriver webDriver = seleniumRule.getWebDriver();
webDriver.get("https://mycurrentlocation.net/");
By latitudeLocator = By.cssSelector("td#latitude");
seleniumRule
.getDefaultWebDriverWait()
.until(wd -> !wd.findElement(latitudeLocator).getText().isEmpty());
assertThat(webDriver.findElement(latitudeLocator).getText(),is("48.20102"));
assertThat(webDriver.findElement(By.cssSelector("td#longitude")).getText(),is("15.62025"));
}
示例10: 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);
}
}
示例11: getObject
import org.openqa.selenium.By; //导入方法依赖的package包/类
/**
* @param p
* @param type
* @param value
* @return
*/
private By getObject(Properties p, String type, String value) {
//System.out.println("DEBUG---PropertyName: " + type + "----DEBUG");
//System.out.println("DEBUG---PropertyValue: " + value + "----DEBUG");
By toBeReturned = null;
String str = type.toLowerCase();
switch(str) {
case "classname":
toBeReturned = By.className(p.getProperty(value));
break;
case "css":
toBeReturned = By.cssSelector(p.getProperty(value));
break;
case "id":
toBeReturned = By.id(p.getProperty(value));
break;
case "linktext":
toBeReturned = By.linkText(p.getProperty(value));
break;
case "name":
toBeReturned = By.name(p.getProperty(value));
break;
case "partiallink":
toBeReturned = By.partialLinkText(p.getProperty(value));
break;
case "tagname":
toBeReturned = By.tagName(p.getProperty(value));
break;
case "xpath":
break;
default:
//TODO
}
return toBeReturned;
}
示例12: 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);
}
示例13: executeAfterJSPreconditionHasBeenSatisfied
import org.openqa.selenium.By; //导入方法依赖的package包/类
@Override
public void executeAfterJSPreconditionHasBeenSatisfied(WebDriver driver, ReplayingState state) {
By byCss = By.cssSelector(cssSelector);
WebElement webElement = driver.findElement(byCss);
webElement.click();
}
示例14: find
import org.openqa.selenium.By; //导入方法依赖的package包/类
/**
* Return a By instance, which is used by findElement()/findElements()
* method to retrieve the element(s). The locators in object repository are
* specified as locator_name=LocatorStrategy,ActualLocatorValue, where
* LocatorStrategy can be 'ID', 'NAME',
* 'CSS_SELECTOR','XPATH','LINK_TEXT','PARTIAL_LINK_TEXT', 'CLASS_NAME',
* 'TAG_NAME'. Ex. mail_link=XPATH,//a[text()='Mail'].
*
* @param locator
* - locator name in object repository
* @return - By instance
* @throws PropertyNotFoundException
* - throw this exception when declared locator is not found in
* object repository
* @throws InvalidLocatorStrategyException
* - throw this exception when locator strategy is wrong. Valid
* locator strategies are 'ID', 'XPATH', 'NAME', 'CSS_SELECTOR',
* 'CLASS_NAME', 'LINK_TEXT', 'PARTIAL_LINK_TEXT' and 'TAG_NAME'
*/
public static By find(String locator) throws PropertyNotFoundException, InvalidLocatorStrategyException
{
locator = props.getProperty(locator);
if (locator.isEmpty() || locator == null)
{
throw new PropertyNotFoundException("Locator value can not be null or empty!");
}
LocatorStrategy strategy = LocatorStrategy.valueOf(locator.split(",")[0]);
String actualLocator = locator.split(",")[1];
By by = null;
switch (strategy)
{
case ID:
by = By.id(actualLocator);
break;
case XPATH:
by = By.xpath(actualLocator);
break;
case NAME:
by = By.name(actualLocator);
break;
case TAG_NAME:
by = By.tagName(actualLocator);
break;
case CSS_SELECTOR:
by = By.cssSelector(actualLocator);
break;
case CLASS_NAME:
by = By.className(actualLocator);
break;
case LINK_TEXT:
by = By.linkText(actualLocator);
break;
case PARTIAL_LINK_TEXT:
by = By.partialLinkText(actualLocator);
break;
default:
throw new InvalidLocatorStrategyException("Unknown locator strategy '" + strategy + "'");
}
return by;
}
示例15: getByCss
import org.openqa.selenium.By; //导入方法依赖的package包/类
@SProperty(name = "css")
public By getByCss(String css) {
return By.cssSelector(css);
}