List of usage examples for org.openqa.selenium WebDriver manage
Options manage();
From source file:edu.samplu.common.WebDriverUtil.java
License:Educational Community License
/** * Wait for the given amount of seconds, for the given by, using the given driver. The message is displayed if the * by cannot be found. No action is performed on the by, so it is possible that the by found is not visible or enabled. * * @param driver WebDriver/*from w w w . j ava 2 s .co m*/ * @param waitSeconds int * @param by By * @param message String * @throws InterruptedException */ public static void waitFor(WebDriver driver, int waitSeconds, By by, String message) throws InterruptedException { driver.manage().timeouts().implicitlyWait(waitSeconds, TimeUnit.SECONDS); Thread.sleep(1000); driver.findElement(by); // NOTICE just the find, no action, so by is found, but might not be visible or enabled. driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS); }
From source file:edu.samplu.common.WebDriverUtil.java
License:Educational Community License
/** * Wait for the given amount of seconds, for the given by, using the given driver. The message is displayed if the * by cannot be found. No action is performed on the by, so it is possible that the by found is not visible or enabled. * * @param driver WebDriver//from www .j av a 2s . co m * @param waitSeconds int * @param by By * @param message String * @throws InterruptedException */ public static void waitFors(WebDriver driver, int waitSeconds, By by, String message) throws InterruptedException { driver.manage().timeouts().implicitlyWait(waitSeconds, TimeUnit.SECONDS); Thread.sleep(1000); driver.findElements(by); // NOTICE just the find, no action, so by is found, but might not be visible or enabled. driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS); }
From source file:edu.umd.cs.guitar.replayer2.WebReplayerMonitor2.java
License:Open Source License
/** * Get component using their GUI identification properties * <p>//from w ww. java2 s . c o m * * @return the component if found and null if not found */ @Override public GComponent getComponent(GApplication application, ComponentType window, ComponentType component) { if (!(application instanceof WebApplication)) throw new ReplayerConstructionException(); WebApplication webApplication = (WebApplication) application; WebDriver driver = webApplication.getDriver(); String xpathExpression = getXpathFromComponent(component); GUITARLog.log.debug("xPath Expression: " + xpathExpression); String currentHandler = driver.getWindowHandle(); driver.manage().timeouts().implicitlyWait(2000, TimeUnit.MILLISECONDS); // Scan all open window for the desired element for (String windowHandler : driver.getWindowHandles()) { try { driver.switchTo().window(windowHandler); if (isSearchWithinWindow) { ComponentType windowComponent = window; ComponentTypeWrapper windowComponentWrapper = new ComponentTypeWrapper(windowComponent); String windowTitle = windowComponentWrapper.getFirstValueByName(GUITARConstants.TITLE_TAG_NAME); windowTitle = normalizeURL(windowTitle); String url = driver.getCurrentUrl(); url = normalizeURL(url); if (!windowTitle.equals(url)) { continue; } } WebElement element = driver.findElement(By.xpath(xpathExpression)); GComponent webComponent = new WebComponent(element, null, null, null); GUITARLog.log.debug("Elemement FOUND in: " + driver.getCurrentUrl()); return webComponent; } catch (org.openqa.selenium.NoSuchElementException e) { GUITARLog.log.debug("Elemement NOT found in: " + driver.getCurrentUrl()); } } driver.switchTo().window(currentHandler); return null; }
From source file:edu.usc.cs.ir.htmlunit.handler.HtmlUnitWebDriver.java
License:Apache License
public static WebDriver getDriverForPage(String url) { long pageLoadTimout = 3; enableJavascript = true;/* w ww .ja v a 2 s .c o m*/ enableCss = false; javascriptTimeout = 13500; int redirects = 4; enableRedirect = redirects <= 0 ? false : true; maxRedirects = redirects; WebDriver driver = null; try { driver = new HtmlUnitWebDriver(); driver.manage().timeouts().pageLoadTimeout(pageLoadTimout, TimeUnit.SECONDS); driver.get(url); } catch (Exception e) { if (e instanceof TimeoutException) { System.out.println("HtmlUnit WebDriver: Timeout Exception: Capturing whatever loaded so far..."); return driver; } cleanUpDriver(driver); throw new RuntimeException(e); } return driver; }
From source file:edu.usc.cs.ir.selenium.handler.Arguntrader.java
License:Apache License
public static void main(String[] args) { Arguntrader glocktalk = new Arguntrader(); FirefoxProfile profile = new FirefoxProfile(); profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, "localhost"); profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", "false"); profile.setPreference("permissions.default.stylesheet", 1); profile.setPreference("permissions.default.image", 1); FirefoxBinary binary = new FirefoxBinary(); binary.setTimeout(TimeUnit.SECONDS.toMillis(180)); WebDriver driver = new FirefoxDriver(binary, profile); driver.manage().timeouts().pageLoadTimeout(10000, TimeUnit.MILLISECONDS); try {//from w ww . jav a 2 s.co m driver.get("http://arguntrader.com/viewforum.php?f=8"); System.out.println(new String(glocktalk.processDriver(driver).getBytes("UTF-8"))); } catch (Exception e) { if (e instanceof TimeoutException) { System.out.println("Timeout Exception"); try { System.out.println(new String(glocktalk.processDriver(driver).getBytes("UTF-8"))); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } e.printStackTrace(); } finally { if (driver != null) { driver.close(); driver.quit(); } } }
From source file:edu.usc.cs.ir.selenium.handler.Glocktalk.java
License:Apache License
public static void main(String[] args) { Glocktalk glocktalk = new Glocktalk(); FirefoxProfile profile = new FirefoxProfile(); profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, "localhost"); profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", "false"); profile.setPreference("permissions.default.stylesheet", 1); profile.setPreference("permissions.default.image", 1); FirefoxBinary binary = new FirefoxBinary(); binary.setTimeout(TimeUnit.SECONDS.toMillis(180)); WebDriver driver = new FirefoxDriver(binary, profile); driver.manage().timeouts().pageLoadTimeout(10000, TimeUnit.MILLISECONDS); try {/*from www. j av a 2 s .c o m*/ driver.get("http://www.glocktalk.com/media?page=6"); System.out.println(new String(glocktalk.processDriver(driver).getBytes("UTF-8"))); } catch (Exception e) { if (e instanceof TimeoutException) { System.out.println("Timeout Exception"); try { System.out.println(new String(glocktalk.processDriver(driver).getBytes("UTF-8"))); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } //e.printStackTrace(); } finally { if (driver != null) { driver.close(); driver.quit(); } } }
From source file:entities.GPTPlanet.java
@Override public void setDriver(WebDriver driver) { this.driver = driver; driver.manage().window().setSize(new Dimension(400, 300)); }
From source file:FacebookRequest.Facebook.java
public FacebookAccount login(String u, String p) throws IOException { FacebookAccount myFacebook = new FacebookAccount(); WebDriver driver = new HtmlUnitDriver(BrowserVersion.CHROME, true); driver.get("https://m.facebook.com/"); driver.findElement(By.name("email")).sendKeys(u); driver.findElement(By.name("pass")).sendKeys(p); driver.findElement(By.name("login")).click(); String HTMLSource = driver.getPageSource(); Set<Cookie> cookies = driver.manage().getCookies(); driver.close();/* w w w. j av a2s. c o m*/ Document doc = Jsoup.parse(HTMLSource); Elements doc_inputs = doc.select("input[name=fb_dtsg]"); Pattern DTSG_Pattern = Pattern.compile("(\\w{12}\\:\\w{12})"); if (doc_inputs.isEmpty()) return null; String DTSG = doc_inputs.first().attr("value"); if (!DTSG_Pattern.matcher(DTSG).find()) return null; myFacebook.setDTSH(DTSG); String myCookie = ""; for (Cookie cookie : cookies) myCookie = myCookie + cookie.getName() + "=" + cookie.getValue() + "; "; myFacebook.setCookie(myCookie); //System.out.println(myFacebook.getCookie()+"\n"+myFacebook.getDTSH()); return myFacebook; }
From source file:fbapi.FBAPI.java
/** * @param args the command line arguments *///from w ww. j a v a2 s.c o m public static void main(String[] args) { // TODO code application logic here //https://developers.facebook.com/apps/YOUR_APP_ID/fb-login/ //https://www.facebook.com/v2.5/dialog/oauth?client_id=XXXXXXXXXXXXXXX&redirect_uri=http%3A%2F%2Fphotovote.dev%2Fauth%2Ffacebook%2Fcallback&scope=email&response_type=code&state=0ztcKhmWwFLtj72TWE8uOKTcf65JmePtG95MZLDD //https://www.facebook.com/v2.5/dialog/oauth?client_id=723262031081656&redirect_uri=http://taiwannoc.net/cgione&scope=email&response_type=code&state=0ztcKhmWwFLtj72TWE8uOKTcf65JmePtG95MZLDD //https://developers.facebook.com/apps/723262031081656/fb-login/ /*"http://www.facebook.com/dialog/oauth?" + "client_id=" + FB_APP_ID + "&redirect_uri=" + URLEncoder.encode(REDIRECT_URI, "UTF-8") + "&scope=public_profile";*/ //http://www.facebook.com/dialog/oauth?client_id=723262031081656&redirect_uri=http://taiwannoc.net/cgione&scope=public_profile String strAPPID = "723262031081656"; String strRedirectURL = "http://taiwannoc.net/cgione"; String strAuthUrl = "https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=" + strAPPID + "&redirect_uri=" + strRedirectURL + "&scope=user_about_me," + "user_actions.books,user_actions.fitness,user_actions.music,user_actions.news,user_actions.video,user_birthday,user_education_history," + "user_events,user_photos,user_friends,user_games_activity,user_hometown,user_likes,user_location,user_photos,user_relationship_details," + "user_relationships,user_religion_politics,user_status,user_tagged_places,user_videos,user_website,user_work_history,ads_management,ads_read,email," + "manage_pages,publish_actions,read_insights,user_friends,read_page_mailboxes,rsvp_event"; System.out.println(strAuthUrl); //System.setProperty("webdriver.chrome.driver", "chromedriver"); System.setProperty("webdriver.chrome.driver", "geckodriver"); //WebDriver driver = new ChromeDriver(); WebDriver driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.get(strRedirectURL); boolean isRunning = true; while (isRunning) { System.out.println("CURRENT_URL: " + driver.getCurrentUrl()); if (driver.getCurrentUrl().contains("facebook.com")) { String strURL = driver.getCurrentUrl(); System.out.println("STR_URL: " + strURL); driver.quit(); } isRunning = false; } }
From source file:fll.web.IntegrationTestUtils.java
License:Open Source License
/** * Create a web driver and set appropriate timeouts on it. *//*from ww w.jav a 2s. com*/ public static WebDriver createWebDriver(final WebDriverType type) { final WebDriver selenium; switch (type) { case FIREFOX: selenium = createFirefoxWebDriver(); break; case CHROME: selenium = createChromeWebDriver(); break; default: throw new IllegalArgumentException("Unknown web driver type: " + type); } selenium.manage().timeouts().implicitlyWait(WAIT_FOR_PAGE_LOAD_MS, TimeUnit.MILLISECONDS); selenium.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS); return selenium; }