List of usage examples for org.openqa.selenium.firefox FirefoxDriver findElement
@Override
public WebElement findElement(By by)
From source file:applango.common.services.Applango.genericApplangoWebsiteActions.java
public static void filterReportsDates(FirefoxDriver driver1, months fromMonth, String fromYear, months toMonth, String toYear) throws IOException { logger.info("Filter Report From: " + fromMonth + "/" + fromYear + " till: " + toMonth + "/" + toYear); driver1.findElement(By.id(applangoDropdowns.REPORT_FROM_MONTH.getValue())).sendKeys(fromMonth.toString()); driver1.findElement(By.id(applangoDropdowns.REPORT_FROM_YEAR.getValue())).sendKeys(fromYear); driver1.findElement(By.id(applangoDropdowns.REPORT_UNTIL_MONTH.getValue())).sendKeys(toMonth.toString()); driver1.findElement(By.id(applangoDropdowns.REPORT_UNTIL_YEAR.getValue())).sendKeys(toYear); }
From source file:com.coinbot.core.Worker.java
License:Open Source License
@Override public void run() { File pathToBinary = new File("/home/jian/Descargas/firefox46/bin/firefox"); // Firefox 46 needed FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary); FirefoxProfile profile = new FirefoxProfile(); FirefoxDriver driver = new FirefoxDriver(ffBinary, profile); CoinbotApplication.ui.workerQueue.addWorker(workerPanel); while (CoinbotApplication.bot.isRunning()) { // Sacamos un "claim" de la cola Claim claim = CoinbotApplication.bot.getClaimQueue().next(); if (claim == null) { continue; }// www . j ava2s . c o m claim.getPanel().reset(); claim.getPanel().getProgressBar().setMaximum(10); workerPanel.addClaim(claim.getPanel()); claim.getPanel().nextStep("Opening URL"); try { driver.manage().timeouts().pageLoadTimeout(12, TimeUnit.SECONDS); driver.navigate().to(new URL(claim.getFaucet().getUrl())); } catch (MalformedURLException e) { e.printStackTrace(); continue; } catch (TimeoutException e) { // Busca un elemento, si no lo encuentra que vuelva a cargar e.printStackTrace(); } // Detectando captcha claim.getPanel().nextStep("Detecting Captcha"); CaptchaDetector captchaDetector = new CaptchaDetector(); CaptchaService captcha = null; try { captcha = captchaDetector.find(driver, driver.findElement(By.tagName("body"))); } catch (NoSuchElementException ex) { ex.printStackTrace(); claim.getPanel().nextStep("Body not found!"); continue; } catch (UnrecognizedCaptcha ex) { ex.printStackTrace(); claim.getPanel().nextStep("Captcha not recognized."); continue; } catch (Exception ex) { continue; } claim.getPanel().nextStep("Trying auto resolving"); // Intentamos buscar el hash en la DB CaptchaHash ch = new CaptchaHash(captcha); String answer = CoinbotApplication.captchaDatabase.getAnswer(ch.getHash()); // Si no enctramos la respuesta en la bd se la pedimos al usuario if (answer == null) { claim.getPanel().nextStep("Waiting for captcha answer ..."); // Encolar captcha CoinbotApplication.bot.getCaptchaQueue().toQueue(captcha); // Esperar la resolucion del captcha CaptchaTimer timer = new CaptchaTimer(captcha, 35); timer.start(); // Esperamos a la resolucion while (!timer.isExpired() && !captcha.resolved()) { CoinbotApplication.ui.captchaQueue.getCaptchaPanel(captcha).setTimer(timer.getSecondsLeft()); } if (!captcha.resolved()) { CoinbotApplication.captchaDatabase.addCaptcha(ch); continue; } } // Guardamos el captcha en la DB CoinbotApplication.captchaDatabase.addCaptcha(new CaptchaHash(captcha)); // Y la imagen en un archivo try { ImageIO.write(captcha.getImage(), "png", new File("coinbot/captchas/" + ch.getHash() + ".png")); } catch (IOException e) { e.printStackTrace(); } // Envia la respuesta al input captcha.answerToInput(driver); // Desencolar captcha CoinbotApplication.bot.getCaptchaQueue().deQueue(captcha); // Escribir address claim.getPanel().nextStep("Detecting input address"); InputAddressDetector iad = new InputAddressDetector(driver); iad.insertAddress(claim.getBtcAddress()); //claim.getPanel().nextStep("Detecting Antibot"); // Detectar antibot (puzzle no soportado) // Resolver antibot // submit claim.getPanel().nextStep("Submiting ..."); WebElement submit = driver.findElement(By.id("address")); submit.submit(); claim.getPanel().nextStep("Checking response"); //claim.getPanel().nextStep("Successfull claim!"); /*WebElement out = null; try { out = driver.findElement(By.className("alert-success")); } catch (NoSuchElementException e) { } try { out = driver.findElement(By.className("alert-danger")); } catch (NoSuchElementException e) { } */ //claim.getPanel().nextStep("Failed claim!"); claim.getPanel().done(); workerPanel.removeClaim(claim.getPanel()); claim.getTimer().done(2000, 1); CoinbotApplication.bot.getClaimQueue().toQueue(claim); try { Thread.sleep(25000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { driver.close(); } catch (Exception e) { } CoinbotApplication.ui.workerQueue.removeWorker(workerPanel); System.out.println("Worker " + workerId + " end work!"); }
From source file:com.vaadin.testbench.TestBenchDriverTest.java
@Test public void testTestBenchDriverActsAsProxy() { FirefoxDriver mockDriver = createMock(FirefoxDriver.class); mockDriver.close();/*www .j ava 2s . c o m*/ expectLastCall().once(); WebElement mockElement = createNiceMock(WebElement.class); expect(mockDriver.findElement(isA(By.class))).andReturn(mockElement); List<WebElement> elements = Arrays.asList(mockElement); expect(mockDriver.findElements(isA(By.class))).andReturn(elements); mockDriver.get("foo"); expectLastCall().once(); expect(mockDriver.getCurrentUrl()).andReturn("foo"); expect(mockDriver.getPageSource()).andReturn("<html></html>"); expect(mockDriver.getTitle()).andReturn("bar"); expect(mockDriver.getWindowHandle()).andReturn("baz"); Set<String> handles = new HashSet<String>(); expect(mockDriver.getWindowHandles()).andReturn(handles); Options mockOptions = createNiceMock(Options.class); expect(mockDriver.manage()).andReturn(mockOptions); Navigation mockNavigation = createNiceMock(Navigation.class); expect(mockDriver.navigate()).andReturn(mockNavigation); mockDriver.quit(); expectLastCall().once(); expect(((JavascriptExecutor) mockDriver).executeScript(anyObject(String.class))).andStubReturn(true); TargetLocator mockTargetLocator = createNiceMock(TargetLocator.class); expect(mockDriver.switchTo()).andReturn(mockTargetLocator); replay(mockDriver); // TestBenchDriverProxy driver = new TestBenchDriverProxy(mockDriver); WebDriver driver = TestBench.createDriver(mockDriver); driver.close(); By mockBy = createNiceMock(By.class); assertTrue(driver.findElement(mockBy) instanceof TestBenchElementCommands); assertTrue(driver.findElements(mockBy).get(0) instanceof TestBenchElementCommands); driver.get("foo"); assertEquals("foo", driver.getCurrentUrl()); assertEquals("<html></html>", driver.getPageSource()); assertEquals("bar", driver.getTitle()); assertEquals("baz", driver.getWindowHandle()); assertEquals(handles, driver.getWindowHandles()); assertEquals(mockOptions, driver.manage()); assertEquals(mockNavigation, driver.navigate()); driver.quit(); assertEquals(mockTargetLocator, driver.switchTo()); verify(mockDriver); }
From source file:com.vaadin.testbench.TestBenchDriverTest.java
@Test public void testDisableWaitForVaadin() { Capabilities mockCapabilities = createNiceMock(Capabilities.class); expect(mockCapabilities.getBrowserName()).andReturn("firefox").anyTimes(); FirefoxDriver mockFF = createMock(FirefoxDriver.class); expect(mockFF.getCapabilities()).andReturn(mockCapabilities).anyTimes(); expect(mockFF.executeScript(contains("clients[client].isActive()"))).andReturn(true).once(); WebElement mockElement = createNiceMock(WebElement.class); expect(mockFF.findElement(isA(By.class))).andReturn(mockElement).times(2); replay(mockFF, mockElement, mockCapabilities); TestBenchDriverProxy tb = (TestBenchDriverProxy) TestBench.createDriver(mockFF); tb.disableWaitForVaadin();/*from ww w.ja v a 2s. c om*/ WebElement testBenchElement = tb.findElement(By.id("foo")); tb.enableWaitForVaadin(); testBenchElement = tb.findElement(By.id("foo")); verify(mockFF, mockElement); }
From source file:com.zhao.crawler.util.CookieUtil.java
License:Open Source License
/** * csdn??cookies?//from ww w . j a v a2 s. co m * * @param username * ?? * @param password * ? * @param geckodriverpath * gecko?https://github.com/mozilla/geckodriver * @param savecookiepath * cookies? * @throws Exception */ public static void firfoxDriverGetCookies(String username, String password, String geckodriverpath, String savecookiepath) throws Exception { // ??? System.setProperty("webdriver.gecko.driver", geckodriverpath); FirefoxDriver driver = new FirefoxDriver(); String baseUrl = "http://kaixin65.com/member.php?mod=logging&action=login&infloat=yes&handlekey=login&inajax=1&ajaxtarget=fwin_content_login"; // url driver.get(baseUrl); // ? driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); // ?? WebElement elemUsername = driver.findElement(By.name("username")); WebElement elemPassword = driver.findElement(By.name("password")); WebElement btn = driver.findElement(By.className("logging")); WebElement rememberMe = driver.findElement(By.id("rememberMe")); // ?? elemUsername.sendKeys(username); elemPassword.sendKeys(password); rememberMe.click(); // ??? btn.submit(); Thread.sleep(5000); driver.get("http://msg.csdn.net/"); Thread.sleep(5000); // ?cookies driver.manage().getCookies(); Set<org.openqa.selenium.Cookie> cookies = driver.manage().getCookies(); System.out.println("Size: " + cookies.size()); Iterator<org.openqa.selenium.Cookie> itr = cookies.iterator(); CookieStore cookieStore = new BasicCookieStore(); while (itr.hasNext()) { Cookie cookie = itr.next(); BasicClientCookie bcco = new BasicClientCookie(cookie.getName(), cookie.getValue()); bcco.setDomain(cookie.getDomain()); bcco.setPath(cookie.getPath()); cookieStore.addCookie(bcco); } // ? ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File(savecookiepath))); oos.writeObject(cookieStore); oos.close(); }
From source file:org.ado.picasa.Main.java
License:Apache License
private static void downloadPhoto(FirefoxDriver driver, String href) { try {//from w ww.ja v a 2 s. c om driver.navigate().to(href); TimeUnit.SECONDS.sleep(1); driver.executeScript( "document.getElementsByClassName('goog-inline-block goog-toolbar-menu-button')[2].style['display']=''"); driver.findElement(By.xpath("//div[@class='goog-inline-block goog-toolbar-menu-button'][3]")).click(); TimeUnit.MILLISECONDS.sleep(200); driver.findElement(By.xpath("//div[@role='menu']")).click(); } catch (Exception e) { System.err.println(String.format("Cannot download photo on '%s'. Skipping ...", href)); e.printStackTrace(); } }
From source file:org.ado.picasa.Main.java
License:Apache License
private static void loginIntoPicasa(String pin, FirefoxDriver driver) throws InterruptedException { driver.get("https://picasaweb.google.com"); driver.findElement(new By.ByName("Email")).sendKeys(System.getenv("GOOGLE_ACCOUNT"), Keys.ENTER); TimeUnit.SECONDS.sleep(1);//from ww w . j ava2s.c om driver.findElement(new By.ByName("Passwd")).sendKeys(System.getenv("GOOGLE_PASSWORD"), Keys.ENTER); TimeUnit.SECONDS.sleep(1); if (StringUtils.isNotBlank(pin)) { driver.findElement(new By.ByName("Pin")).sendKeys(pin, Keys.ENTER); TimeUnit.SECONDS.sleep(1); } }