Search in sources :

Example 1 with WebElement

use of org.openqa.selenium.WebElement in project webmagic by code4craft.

the class SeleniumTest method testSelenium.

@Ignore("need chrome driver")
@Test
public void testSelenium() {
    System.getProperties().setProperty("webdriver.chrome.driver", "/Users/yihua/Downloads/chromedriver");
    Map<String, Object> contentSettings = new HashMap<String, Object>();
    contentSettings.put("images", 2);
    Map<String, Object> preferences = new HashMap<String, Object>();
    preferences.put("profile.default_content_settings", contentSettings);
    DesiredCapabilities caps = DesiredCapabilities.chrome();
    caps.setCapability("chrome.prefs", preferences);
    caps.setCapability("chrome.switches", Arrays.asList("--user-data-dir=/Users/yihua/temp/chrome"));
    WebDriver webDriver = new ChromeDriver(caps);
    webDriver.get("http://huaban.com/");
    WebElement webElement = webDriver.findElement(By.xpath("/html"));
    System.out.println(webElement.getAttribute("outerHTML"));
    webDriver.close();
}
Also used : WebDriver(org.openqa.selenium.WebDriver) HashMap(java.util.HashMap) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) WebElement(org.openqa.selenium.WebElement) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with WebElement

use of org.openqa.selenium.WebElement in project head by mifos.

the class SeleniumTest method testSearchMifosOnGoogle.

@Test
public void testSearchMifosOnGoogle() throws Exception {
    WebDriver wd = new FirefoxDriver();
    try {
        wd.get("http://www.google.com");
        WebElement element = wd.findElement(By.name("q"));
        element.sendKeys("Mifos");
        element.submit();
    } finally {
        wd.quit();
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test)

Example 3 with WebElement

use of org.openqa.selenium.WebElement in project sonarqube by SonarSource.

the class ByCssSelectorOrByNameOrById method findElement.

@Override
public WebElement findElement(SearchContext context) {
    WebElement element;
    if (validCssSelector(selector)) {
        element = ((FindsByCssSelector) context).findElementByCssSelector(quoteCss(selector));
        if (element != null) {
            return element;
        }
    }
    element = ((FindsByName) context).findElementByName(selector);
    if (element != null) {
        return element;
    }
    element = ((FindsById) context).findElementById(selector);
    if (element != null) {
        return element;
    }
    return null;
}
Also used : WebElement(org.openqa.selenium.WebElement)

Example 4 with WebElement

use of org.openqa.selenium.WebElement in project cucumber-jvm by cucumber.

the class RentACarSupport method getAvailableNumberOfCars.

public int getAvailableNumberOfCars() {
    WebDriver driver = new HtmlUnitDriver();
    try {
        driver.get("http://localhost:9878/rentit/available");
        WebElement availableCars = driver.findElement(By.id("availableCars"));
        String availableCarsString = availableCars.getText();
        return Integer.parseInt(availableCarsString);
    } finally {
        driver.close();
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver)

Example 5 with WebElement

use of org.openqa.selenium.WebElement in project cucumber-jvm by cucumber.

the class RentACarSupport method rentACar.

public void rentACar() {
    WebDriver driver = new HtmlUnitDriver();
    try {
        driver.get("http://localhost:9878/rentit/rent");
        WebElement rentButton = driver.findElement(By.id("rentButton"));
        rentButton.click();
    } finally {
        driver.close();
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver)

Aggregations

WebElement (org.openqa.selenium.WebElement)3118 By (org.openqa.selenium.By)784 Test (org.junit.Test)649 WebDriver (org.openqa.selenium.WebDriver)240 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)183 Test (org.testng.annotations.Test)169 ChromeBrowserTest (com.vaadin.flow.testutil.ChromeBrowserTest)167 Actions (org.openqa.selenium.interactions.Actions)151 ArrayList (java.util.ArrayList)139 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)130 Select (org.openqa.selenium.support.ui.Select)130 NoSuchElementException (org.openqa.selenium.NoSuchElementException)101 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)88 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)80 WebDriverException (org.openqa.selenium.WebDriverException)79 List (java.util.List)74 NgWebElement (com.github.sergueik.jprotractor.NgWebElement)63 URL (java.net.URL)62 TestBenchElement (com.vaadin.testbench.TestBenchElement)60 ExpectedCondition (org.openqa.selenium.support.ui.ExpectedCondition)59