@Test public void testGoogle() throws Exception { try { WebDriver driver = new AndroidDriver(); // And now use this to visit Google driver.get("http://www.google.com"); // Find the text input element by its name WebElement element = driver.findElement(By.name("q")); // Enter something to search for element.sendKeys("Cheese!"); // Now submit the form. WebDriver will find the form for us from the element element.submit(); // Check the title of the page System.out.println("Page title is: " + driver.getTitle()); driver.quit(); } catch (Exception e) { e.printStackTrace(); } }
public void setDriver() { try { driver = new AndroidDriver(); } catch(UnreachableBrowserException e) { System.out.println("Could not set driver..."); } }
/** * Build a new WebDriver based EmbeddedBrowser. * * @return the new build WebDriver based embeddedBrowser */ @Override public EmbeddedBrowser get() { LOGGER.debug("Setting up a Browser"); // Retrieve the config values used ImmutableSortedSet<String> filterAttributes = configuration.getCrawlRules().getPreCrawlConfig().getFilterAttributeNames(); long crawlWaitReload = configuration.getCrawlRules().getWaitAfterReloadUrl(); long crawlWaitEvent = configuration.getCrawlRules().getWaitAfterEvent(); // Determine the requested browser type EmbeddedBrowser browser = null; switch (configuration.getBrowserConfig().getBrowsertype()) { case FIREFOX: browser = newFireFoxBrowser(filterAttributes, crawlWaitReload, crawlWaitEvent); break; case INTERNET_EXPLORER: browser = WebDriverBackedEmbeddedBrowser.withDriver(new InternetExplorerDriver(), filterAttributes, crawlWaitEvent, crawlWaitReload); break; case CHROME: browser = newChromeBrowser(filterAttributes, crawlWaitReload, crawlWaitEvent); break; case REMOTE: browser = WebDriverBackedEmbeddedBrowser.withRemoteDriver(configuration .getBrowserConfig().getRemoteHubUrl(), filterAttributes, crawlWaitEvent, crawlWaitReload); break; case ANDROID: browser = WebDriverBackedEmbeddedBrowser.withDriver(new AndroidDriver(), filterAttributes, crawlWaitEvent, crawlWaitReload); break; default: throw new IllegalStateException("Unrecognized browsertype " + configuration.getBrowserConfig().getBrowsertype()); } plugins.runOnBrowserCreatedPlugins(browser); return browser; }
@Before public void setUp() throws Exception { driver = new AndroidDriver(); baseUrl = "http://www.baidu.com/"; driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); }