本文整理汇总了Java中org.openqa.selenium.WebElement类的典型用法代码示例。如果您正苦于以下问题:Java WebElement类的具体用法?Java WebElement怎么用?Java WebElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebElement类属于org.openqa.selenium包,在下文中一共展示了WebElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: click
import org.openqa.selenium.WebElement; //导入依赖的package包/类
public void click() 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"));
element1.click();
AssertJUnit.assertTrue(buttonClicked);
buttonClicked = false;
new Actions(driver).click().perform();
AssertJUnit.assertTrue(buttonClicked);
AssertJUnit.assertTrue(buttonMouseActions.toString().contains("clicked(1)"));
buttonMouseActions.setLength(0);
new Actions(driver).contextClick().perform();
AssertJUnit.assertTrue(buttonMouseActions.toString(), buttonMouseActions.toString().contains("pressed(3-popup)"));
}
示例2: getLocation
import org.openqa.selenium.WebElement; //导入依赖的package包/类
public void getLocation() 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"));
Point location = element1.getLocation();
java.awt.Point p = EventQueueWait.call(button, "getLocation");
AssertJUnit.assertEquals(p.x, location.x);
AssertJUnit.assertEquals(p.y, location.y);
}
示例3: getRowCount
import org.openqa.selenium.WebElement; //导入依赖的package包/类
/**
* @return how many rows this table has
*/
@Override
@PublicAtsApi
public int getRowCount() {
new HiddenHtmlElementState(this).waitToBecomeExisting();
String css = this.getElementProperty("_css");
List<WebElement> elements = null;
if (!StringUtils.isNullOrEmpty(css)) {
css += " tr";
elements = webDriver.findElements(By.cssSelector(css));
} else {
// get elements matching the following xpath
elements = webDriver.findElements(By.xpath(properties.getInternalProperty(HtmlElementLocatorBuilder.PROPERTY_ELEMENT_LOCATOR)
+ "/tr | "
+ properties.getInternalProperty(HtmlElementLocatorBuilder.PROPERTY_ELEMENT_LOCATOR)
+ "/*/tr"));
}
return elements.size();
}
示例4: getElement
import org.openqa.selenium.WebElement; //导入依赖的package包/类
private static WebElement getElement(WebDriver driver, By by, int current){
WebElement element = null;
while(true) {
try {
element = driver.findElement(by);
} catch (Exception e){
//might happen due to Github blocking crawling
try {
long time = 60_000;
System.out.println("Cannot find -> "+by.toString()+"\n Going to wait for "+time+"ms");
Thread.sleep(time);
openPagedSearchResult(driver, current);
} catch (InterruptedException e1) {
}
continue;
}
break;
}
return element;
}
示例5: isEnabled
import org.openqa.selenium.WebElement; //导入依赖的package包/类
public void isEnabled() 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"));
AssertJUnit.assertTrue(element1.isEnabled());
SwingUtilities.invokeAndWait(new Runnable() {
@Override public void run() {
button.setEnabled(false);
}
});
EventQueueWait.waitTillDisabled(button);
AssertJUnit.assertFalse(element1.isEnabled());
}
示例6: decorate
import org.openqa.selenium.WebElement; //导入依赖的package包/类
@Override
public Object decorate(ClassLoader loader, Field field) {
By selector = new Annotations(field).buildBy();
if (selector instanceof ByIdOrName) {
// throw new IllegalArgumentException("Please define locator for " + field);
return decorateWithAppium(loader, field);
} else if (WebElement.class.isAssignableFrom(field.getType())) {
return ElementFinder.wrap(searchContext, selector, 0);
} else if (ElementsCollection.class.isAssignableFrom(field.getType())) {
return new ElementsCollection(new BySelectorCollection(searchContext, selector));
} else if (ElementsContainer.class.isAssignableFrom(field.getType())) {
return createElementsContainer(selector, field);
} else if (isDecoratableList(field, ElementsContainer.class)) {
return createElementsContainerList(field);
} else if (isDecoratableList(field, SelenideElement.class)) {
return SelenideElementListProxy.wrap(factory.createLocator(field));
}
return decorateWithAppium(loader, field);
}
示例7: atc
import org.openqa.selenium.WebElement; //导入依赖的package包/类
public void atc() {
WebDriverWait wait = new WebDriverWait(driver, 300L);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@class='ffSelectButton' and (.//span[text()[contains(.,'Size')]] or .//span[text()[contains(.,'size')]])]")));
int index = new Random().nextInt(sizes.length);
String sizeToPick = Double.toString(sizes[index]);
for(WebElement e : driver.findElements(By.xpath("//div[@class='ffSelectMenuMid' and .//ul[.//li[.//span[text()[contains(.,'size')]]]]]/ul/li"))) {
String size = e.getText().trim();
if(size != null && size.equals(sizeToPick)) {
e.click();
break;
}
}
}
示例8: setValue
import org.openqa.selenium.WebElement; //导入依赖的package包/类
/**
* select a value
*
* @param value the value to select
*/
@Override
@PublicAtsApi
public void setValue(
String value ) {
new RealHtmlElementState(this).waitToBecomeExisting();
try {
WebElement element = RealHtmlElementLocator.findElement(this);
Select select = new Select(element);
select.selectByVisibleText(value);
} catch (NoSuchElementException nsee) {
throw new SeleniumOperationException("Option with label '" + value + "' not found. ("
+ this.toString() + ")");
}
UiEngineUtilities.sleep();
}
示例9: get_password
import org.openqa.selenium.WebElement; //导入依赖的package包/类
private WebElement get_password() {
WebElement element = null;
if (WebUtilities.waitForElementToAppear(driver, password, logger)) {
element = password;
}
return element;
}
示例10: waitForElementToNotExist
import org.openqa.selenium.WebElement; //导入依赖的package包/类
protected void waitForElementToNotExist(WebElement element) {
new WebDriverWait(getDriverProxy(), 20)
.withMessage("Timed out waiting for element to not exist.")
.until((WebDriver d) -> {
boolean conditionMet = false;
try {
// We don't really care whether it's displayed or not, just if it exists.
element.isDisplayed();
} catch (NoSuchElementException | StaleElementReferenceException e) {
conditionMet = true;
}
return conditionMet;
});
}
示例11: postMessage
import org.openqa.selenium.WebElement; //导入依赖的package包/类
/**
* Posts the given message to the brain chat.
*
* @param message
* The message to post
*/
public void postMessage(final String message) {
updateLastUsage();
switchToWindow();
switchToFrame(CHAT_INPUT_FRAME_NAME);
final WebElement input = new NamePresenceWait(this.mDriver, CHAT_INPUT_NAME).waitUntilCondition();
input.sendKeys(message);
input.sendKeys(Keys.ENTER);
}
示例12: hoverMouseOnWebElement
import org.openqa.selenium.WebElement; //导入依赖的package包/类
public static void hoverMouseOnWebElement(WebDriver driver, ExtentTest logger, WebElement element) {
try {
Actions action = new Actions(driver);
action.moveToElement(element).build().perform();
} catch (Exception e) {
logger.log(LogStatus.ERROR, "Error hovering over the element</br>" + e.getCause());
}
}
示例13: filterHidden
import org.openqa.selenium.WebElement; //导入依赖的package包/类
/**
* Remove hidden elements from specified list
*
* @param elements list of elements
* @return 'true' if no visible elements were found; otherwise 'false'
*/
public static boolean filterHidden(List<WebElement> elements) {
Iterator<WebElement> iter = elements.iterator();
while (iter.hasNext()) {
if ( ! iter.next().isDisplayed()) {
iter.remove();
}
}
return elements.isEmpty();
}
示例14: clicksOnMenus
import org.openqa.selenium.WebElement; //导入依赖的package包/类
public void clicksOnMenus() throws Throwable {
driver = new JavaDriver();
List<WebElement> menus = driver.findElements(By.cssSelector("menu"));
int i = 0;
clicksOnMenu(menus, i++, "Menu 1");
clicksOnMenu(menus, i++, "Menu 2");
clicksOnMenu(menus, i++, "Menu 3");
}
示例15: checkCssClassDoesNotContain
import org.openqa.selenium.WebElement; //导入依赖的package包/类
@Override
public boolean checkCssClassDoesNotContain(WebElement w, String... args) throws Exception {
startTime();
boolean result = currentPage.checkCssClassDoesNotContain(w, args);
this.setNextPage();
return result;
}