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


Java WebElement類代碼示例

本文整理匯總了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)"));
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:20,代碼來源:JavaDriverTest.java

示例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);
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:15,代碼來源:JavaDriverTest.java

示例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();
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:27,代碼來源:HiddenHtmlTable.java

示例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;
    }
 
開發者ID:arcuri82,項目名稱:testing_security_development_enterprise_systems,代碼行數:24,代碼來源:GitCrawler.java

示例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());
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:19,代碼來源:JavaDriverTest.java

示例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);
}
 
開發者ID:codeborne,項目名稱:selenide-appium,代碼行數:21,代碼來源:SelenideAppiumFieldDecorator.java

示例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;
		}
	}	
}
 
開發者ID:Penor,項目名稱:SneakerBot,代碼行數:17,代碼來源:Adidas.java

示例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();
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:23,代碼來源:RealHtmlMultiSelectList.java

示例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;
}
 
開發者ID:anilpandeykiet,項目名稱:POM_HYBRID_FRAMEOWRK,代碼行數:8,代碼來源:FlightReservation_Login.java

示例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;
	});
}
 
開發者ID:3pillarlabs,項目名稱:AutomationFrameworkTPG,代碼行數:15,代碼來源:BasePage.java

示例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);
}
 
開發者ID:ZabuzaW,項目名稱:BrainBridge,代碼行數:16,代碼來源:BrainInstance.java

示例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());
	}
}
 
開發者ID:anilpandeykiet,項目名稱:POM_HYBRID_FRAMEOWRK,代碼行數:9,代碼來源:MouseOperations.java

示例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();
}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:16,代碼來源:WebDriverUtils.java

示例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");
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:9,代碼來源:JMenuHorizontalTest.java

示例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;
}
 
開發者ID:saiscode,項目名稱:kheera,代碼行數:8,代碼來源:TestExecutionController.java


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