List of usage examples for org.openqa.selenium WebDriver get
void get(String url);
From source file:com.java.AppTestType_18_11_2015.java
public void BIDONOWNLOT(WebDriver driver, String fieldText, String value) { try {//w w w .j a v a2 s . co m driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); AMPLOGIN(driver, value); driver.findElement(By.linkText("Lots")).click(); Thread.sleep(4000); new Select(driver.findElement(By.xpath("//select[@name='venueID']"))) .selectByVisibleText("EquipmentOne"); new Select(driver.findElement(By.xpath("//select[@name='offerSrhListingStatus']"))) .selectByVisibleText("Approved"); driver.findElement(By.xpath("//input[@name='find_button']")).click(); driver.findElement(By.xpath("//*[@id='renderView']/table[2]/tbody/tr[1]/td[2]/table/tbody/tr[1]/td/a")) .click(); String EQID = driver .findElement(By.xpath("//td[@class='listdatabold' and text()='Lot Number:']/../td[4]")) .getText(); System.out.println("EQID is: " + EQID); driver.findElement(By.xpath("//td[@class='listdatabold' and text()='Seller:']/../td[2]/a")).click(); Thread.sleep(5000); String SellerMailID = driver.findElement(By.id("id_frm_Email_Address")).getAttribute("value"); System.out.println("SellerMailID is: " + SellerMailID); AMPLOGOUT(driver); driver.get(fieldText); WebDriverWait wait = new WebDriverWait(driver, 30); driver.findElement(By.name("josso_username")).clear(); driver.findElement(By.name("josso_username")).sendKeys(SellerMailID); driver.findElement(By.name("josso_password")).clear(); driver.findElement(By.name("josso_password")).sendKeys("Equipment1$"); driver.findElement(By.xpath("//*[@value='SIGN IN']")).click(); Thread.sleep(4000); driver.findElement(By.id("search")).sendKeys(EQID); driver.findElement(By.xpath("//*[@id='main_search']/button")).click(); Thread.sleep(4000); //driver.findElement(By.xpath("(//*[@name='makeoffer'])[2]")).click(); driver.findElement(By.xpath("(//*[@name='makeoffer'])[2]")).sendKeys("99999999999"); driver.findElement(By.xpath("(//*[contains(@value,'PLACE A BID')])[2]")).click(); Thread.sleep(4000); driver.findElement(By.xpath("(//input[@class='form-control jsOfferInput e1ConfirmInput'])[2]")) .sendKeys("99999999999"); driver.findElement(By.xpath("(//input[@class='btn btn-primary jsConfirmOffer'])[2]")).click(); Thread.sleep(4000); if (driver.findElement(By.tagName("html")).getText() .contains("You are attempting to place a bid on a lot you own, this is not allowed.")) resultDetails.setFlag(true); } catch (Exception e2) { e2.printStackTrace(); resultDetails.setErrorMessage("something went wrong"); resultDetails.setFlag(false); } }
From source file:com.javacreed.examples.misc.Example.java
License:Apache License
public static void main(final String[] args) throws Exception { final String link = "http://www.javacreed.com/"; final File screenShot = new File("screenshot.png").getAbsoluteFile(); Example.LOGGER.debug("Creating Firefox Driver"); final WebDriver driver = new FirefoxDriver(); try {/*from w w w . j av a 2s.c om*/ Example.LOGGER.debug("Opening page: {}", link); driver.get(link); Example.LOGGER.debug("Wait a bit for the page to render"); TimeUnit.SECONDS.sleep(5); Example.LOGGER.debug("Taking Screenshot"); final File outputFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(outputFile, screenShot); Example.LOGGER.debug("Screenshot saved: {}", screenShot); } finally { driver.close(); } Example.LOGGER.debug("done"); }
From source file:com.liferay.cucumber.selenium.BaseWebDriverImpl.java
License:Open Source License
public BaseWebDriverImpl(String browserURL, WebDriver webDriver) { _webDriver = webDriver;/*www .j a v a 2s. com*/ initKeysSpecialChars(); WebDriverHelper.setDefaultWindowHandle(webDriver.getWindowHandle()); WebDriverHelper.setNavigationBarHeight(120); System.setProperty("java.awt.headless", "false"); String outputDirName = _OUTPUT_DIR_NAME; String sikuliImagesDirName = _TEST_DEPENDENCIES_DIR_NAME + "//sikuli//linux//"; String testDependenciesDirName = _TEST_DEPENDENCIES_DIR_NAME; if (OSDetector.isApple()) { sikuliImagesDirName = StringUtil.replace(sikuliImagesDirName, "linux", "osx"); } else if (OSDetector.isWindows()) { outputDirName = StringUtil.replace(outputDirName, "//", "\\"); sikuliImagesDirName = StringUtil.replace(sikuliImagesDirName, "//", "\\"); sikuliImagesDirName = StringUtil.replace(sikuliImagesDirName, "linux", "windows"); testDependenciesDirName = StringUtil.replace(testDependenciesDirName, "//", "\\"); } _outputDirName = outputDirName; _sikuliImagesDirName = sikuliImagesDirName; _testDependenciesDirName = testDependenciesDirName; WebDriver.Options options = webDriver.manage(); WebDriver.Window window = options.window(); window.setSize(new Dimension(1300, 768)); webDriver.get(browserURL); }
From source file:com.liferay.cucumber.selenium.WebDriverHelper.java
License:Open Source License
public static void open(WebDriver webDriver, String url) { String targetURL = url.trim(); if (targetURL.startsWith("/")) { targetURL = PropsValues.PORTAL_URL + targetURL; }/*from w ww .ja v a2 s . c o m*/ webDriver.get(targetURL); if (PropsValues.BROWSER_TYPE.equals("internetexplorer")) { refresh(webDriver); } }
From source file:com.liferay.faces.test.selenium.browser.internal.BrowserDriverImpl.java
License:Open Source License
@Override public void navigateWindowTo(String url) { WebDriver webDriver = getWebDriver(); webDriver.get(url); }
From source file:com.maoyan.pf.webcollector.spider.ShowrateCrawler.java
License:Open Source License
public static void main(String[] args) throws Exception { Executor executor = new Executor() { @Override/*from www . j a va 2s . c o m*/ public void execute(CrawlDatum datum, CrawlDatums next) throws Exception { MongoClient mongoClient = new MongoClient("localhost", 27017); // ? // DBCollection dbCollection = mongoClient.getDB("maoyan_crawler").getCollection("rankings_am"); DB db = mongoClient.getDB("maoyan_crawler"); // ????? Set<String> colls = db.getCollectionNames(); for (String s : colls) { // Collection(?"") if (s.equals("show_rate")) { db.getCollection(s).drop(); } } DBCollection dbCollection = db.getCollection("show_rate"); // ProfilesIni pi = new ProfilesIni(); // FirefoxProfile profile = pi.getProfile("default"); WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.manage().timeouts().pageLoadTimeout(3, TimeUnit.SECONDS); // driver.setJavascriptEnabled(false); System.out.println("??\n"); driver.get(datum.getUrl()); // System.out.println(driver.getPageSource()); List<WebElement> movie_name = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c1 lineDot']")); List<WebElement> boxoffice_rate = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c2 red']")); List<WebElement> visit_pershow = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c3 gray']")); WebElement title = driver.findElement(By.xpath("//p[@id='pieTip']")); for (int i = 0; i < movie_name.size(); i++) { String movie_name_val = movie_name.get(i).getText(); String boxofficerate_val = boxoffice_rate.get(i).getText(); String visit_pershow_val = visit_pershow.get(i).getText(); BasicDBObject dbObject = new BasicDBObject(); dbObject.append("title", title.getText()).append("is_gold", "?") .append("show_type", "?").append("movie_name", movie_name_val) .append("boxoffice_rate", boxofficerate_val).append("visit_pershow", visit_pershow_val); dbCollection.insert(dbObject); } System.out.println("?\n"); WebElement click_gold = driver.findElement(By.id("playPlan_time")); click_gold.click(); String gold_seat = driver.getWindowHandle(); driver.switchTo().window(gold_seat); List<WebElement> movie_name_gold = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c1 lineDot']")); List<WebElement> boxoffice_rate_gold = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c2 red']")); List<WebElement> visit_pershow_gold = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c3 gray']")); WebElement title_gold = driver.findElement(By.xpath("//p[@id='pieTip']")); for (int i = 0; i < movie_name_gold.size(); i++) { String movie_name_val = movie_name_gold.get(i).getText(); String boxofficerate_val = boxoffice_rate_gold.get(i).getText(); String visit_pershow_val = visit_pershow_gold.get(i).getText(); BasicDBObject dbObject = new BasicDBObject(); dbObject.append("title", title_gold.getText()).append("is_gold", "") .append("show_type", "?").append("movie_name", movie_name_val) .append("boxoffice_rate", boxofficerate_val).append("visit_pershow", visit_pershow_val); dbCollection.insert(dbObject); } System.out.println("?\n"); WebElement click_vist = driver.findElement(By.xpath("//*[@id='show--type']")); click_vist.click(); String gold_vist = driver.getWindowHandle(); driver.switchTo().window(gold_vist); List<WebElement> movie_name_gold_visit = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c1 lineDot']")); List<WebElement> boxoffice_rate_gold_visit = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c2 red']")); List<WebElement> visit_pershow_gold_visit = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c3 gray']")); WebElement title_gold_visit = driver.findElement(By.xpath("//p[@id='pieTip']")); for (int i = 0; i < movie_name_gold_visit.size(); i++) { String movie_name_val = movie_name_gold_visit.get(i).getText(); String boxofficerate_val = boxoffice_rate_gold_visit.get(i).getText(); String visit_pershow_val = visit_pershow_gold_visit.get(i).getText(); BasicDBObject dbObject = new BasicDBObject(); dbObject.append("title", title_gold_visit.getText()).append("is_gold", "") .append("show_type", "").append("movie_name", movie_name_val) .append("boxoffice_rate", boxofficerate_val).append("visit_pershow", visit_pershow_val); dbCollection.insert(dbObject); } System.out.println("?\n"); click_gold.click(); String normal_seat = driver.getWindowHandle(); driver.switchTo().window(normal_seat); List<WebElement> movie_name_normal_seat = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c1 lineDot']")); List<WebElement> boxoffice_rate_normal_seat = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c2 red']")); List<WebElement> visit_pershow_normal_seat = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c3 gray']")); WebElement title_normal_seat = driver.findElement(By.xpath("//p[@id='pieTip']")); for (int i = 0; i < movie_name_normal_seat.size(); i++) { String movie_name_val = movie_name_normal_seat.get(i).getText(); String boxofficerate_val = boxoffice_rate_normal_seat.get(i).getText(); String visit_pershow_val = visit_pershow_normal_seat.get(i).getText(); BasicDBObject dbObject = new BasicDBObject(); dbObject.append("title", title_normal_seat.getText()).append("is_gold", "?") .append("show_type", "").append("movie_name", movie_name_val) .append("boxoffice_rate", boxofficerate_val).append("visit_pershow", visit_pershow_val); dbCollection.insert(dbObject); } driver.close(); driver.quit(); mongoClient.close(); } }; //DBDBManager DBManager manager = new BerkeleyDBManager("maoyan"); //Crawler?DBManagerExecutor Crawler crawler = new Crawler(manager, executor); crawler.addSeed("http://pf.maoyan.com/show/rate"); crawler.start(1); }
From source file:com.mx.santander.lh.obpyme.Operacion.OperacionesMarketingSantander.java
public void OperacionesCampaniaMArketing(WebDriver driver) throws InterruptedException, IOException { //OPERACIONES DE MANEJO DE BROWSER driver.manage().window().maximize(); driver.get("http://www.google.com"); //VALIDACION DE ELEMENTOS PARA INICIO DE PRUEBA Thread.sleep(3000);// w w w . j ava 2 s . com if (validacionesMArketing.ValidaElementosMarketingSantander(driver)) { System.out.println("----- INICIA TEST AUTOMATIZADO -----"); System.out.println("------------------------------------"); System.out.println("Caso de prueba: " + datos.RecuperarDatosExcel().getCasoPrueba()); System.out.println(""); //REALIZA LA BUSQUEDA DE LA EMPRESA A LA QUE SE LE VA A REALIZAR EL MARKETING elementos.ElementoTextInputBusqueda(driver).sendKeys(datos.RecuperarDatosExcel().getEmpresaMarketing()); elementos.ElementoTextInputBusqueda(driver).sendKeys(Keys.ENTER); Thread.sleep(3000); System.out.println("----- DATOS DE PRUEBA -----"); System.out.println("---------------------------"); System.out.println("EMPRESA: " + datos.RecuperarDatosExcel().getEmpresaMarketing()); System.out.println("ENLACE TOP 1: " + datos.RecuperarDatosExcel().getPosicionamientoMarketingTopURL()); System.out.println("TOP NUMBER: " + datos.RecuperarDatosExcel().getTopNumber()); System.out.println(""); //VALIDA SI SE ENCONTRARON VALORES EN LA BUSQUEDA. if (validacionesMArketing.ValidaListaElementosResultados(driver)) { List<WebElement> listaElementos = elementos.ListaURLBusqueda(driver); //RECORREMOS LA LISTA DE ELEMENTOS RECUPERADOS PARA IDENTIFICAR SI LA EMPRESA DE MARKETING SE ENCUENTRA EN LA POSICION INDICADA System.out.println("----- RESULTADO DEL TEST AUTOMATIZADO -----"); System.out.println("-------------------------------------------"); int contador = 0; for (WebElement elemento : listaElementos) { contador++; //LA EMPRESA SE ENCUENTRA EN EL TOP TEN if (elemento.getText().equals(datos.RecuperarDatosExcel().getPosicionamientoMarketingTopURL()) && contador == datos.RecuperarDatosExcel().getTopNumber()) { System.out.println("LA EMPRESA SE ENCUENTRA EN EL TOP TEN DE BUSQUEDA EN GOOGLE"); driver.close(); break; } //LA EMPRESA NO SE ENCUENTRA EN EL TOP TEN. if (contador == listaElementos.size()) { System.out .println("LA EMPRESA NO SE ENCUENTRA EN EL TOP TEN INICIAR CAMPAA DE MARKETING"); driver.close(); } } } } else { //NO SE ENCONTRARON LOS ELEMENTOS NECESARIOS PARA COMENZAR CON LA PRUEBA System.out.println("LA BUSQUEDA EN GOOGLE NO SE ENCUENTRA DISPONIBLE POR EL MOMENTO"); } }
From source file:com.mycompany.mavenproject1.main.java
public static void main(String[] args) throws InterruptedException { String exePath = "C:\\Unit Testing\\Drivers\\chromedriver.exe"; Map<String, Object> prefs = new HashMap<String, Object>(); prefs.put("profile.default_content_setting_values.notifications", 2); ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("prefs", prefs); System.setProperty("webdriver.chrome.driver", exePath); WebDriver driver = new ChromeDriver(options); JavascriptExecutor jse = (JavascriptExecutor) driver; WebDriverWait wait = new WebDriverWait(driver, 10); driver.get("https://www.facebook.com"); String actualTitle = driver.getTitle(); if (actualTitle.contentEquals("Facebook - Log In or Sign Up")) { driver.findElement(By.id("email")).sendKeys(""); driver.findElement(By.id("pass")).sendKeys(""); TimeUnit.SECONDS.sleep(1); driver.findElement(By.id("u_0_o")).submit(); System.out.println("Test Passed!"); } else {/*from w w w . j av a2s .com*/ System.out.println("test is failed"); driver.close(); return; } int x = 0; while (x < 2) { jse.executeScript("scroll(0, 100000);"); x++; TimeUnit.SECONDS.sleep(1); } try { jse.executeScript("scroll(0, 0);"); List<WebElement> click = driver.findElements(By.xpath("//*[@class='comment_link _5yxe']")); List<WebElement> Names = driver.findElements(By.xpath("//*[@class=' UFICommentActorName']")); System.out.println(Names.size() + "This is how many elements in Names"); List<WebElement> comments = driver.findElements(By.xpath("//*[@class='UFICommentBody']")); for (WebElement el : click) { if (!el.getText().isEmpty()) { //System.out.println(el.getText()); System.out.println("Attempting to click " + el.getText()); jse.executeScript( "return arguments[0].scrollIntoView(0, document.documentElement.scrollHeight-10);", el); TimeUnit.MILLISECONDS.sleep(500); el.click(); } else { System.out.println("This is what we got from the web element\n"); System.out.println(el.getText()); } } jse.executeScript("int x = 0;" + "scroll(0, 0);"); TimeUnit.SECONDS.sleep(1); for (WebElement el : Names) { jse.executeScript( "return arguments[0].scrollIntoView(0, document.documentElement.scrollHeight-10);", el); TimeUnit.SECONDS.sleep(1); System.out.println(el.getText()); } } catch (NoSuchElementException e) { System.err.println("too slow on the scrolling"); } }
From source file:com.mycompany.newseleniumtest.coba.java
public void latihan(String browser) throws InterruptedException { //Instantiate the webdriver object: WebDriver driver = new FirefoxDriver(); JavascriptExecutor jse = (JavascriptExecutor) driver; //Open the web driver.get("http://dev.uangteman.com/admin/"); driver.manage().window().maximize(); Thread.sleep(1500);//from w ww. j a va2 s .co m driver.findElement(By.name("bu_name")).sendKeys("rahmat_cs"); driver.findElement(By.name("bu_passwd")).sendKeys("testing"); driver.findElement(By.cssSelector("button[class='btn btn-orange btn-squared pull-right ladda-button']")) .click(); Thread.sleep(2500); jse.executeScript("window.scrollBy(0,1500)", ""); jse.executeScript("window.scroll(0,1500)", ""); WebElement scroll = driver.findElement(By.xpath( "/html/body/div[2]/div[2]/div/div[2]/div/div/div[3]/div/div[2]/div/form/table/tbody/tr[1]/td[12]/span")); JavascriptExecutor js = (JavascriptExecutor) driver; jse.executeScript( "document.getElementByxpath('/html/body/div[2]/div[2]/div/div[2]/div/div/div[3]/div/div[2]/div/form/table/tbody/tr[1]/td[12]/span').scrollLeft += 250", ""); //Get page title in selenium webdriver String actual = driver.getTitle(); }
From source file:com.mycompany.selenium.SeleniumExample.java
public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "/Applications/chromedriver"); // Create a new instance of the Firefox driver // Notice that the remainder of the code relies on the interface, // not the implementation. WebDriver driver = new ChromeDriver(); // System.setProperty("webdriver.chrome.driver", "/Users/CosticaTeodor/Downloads/drivers/chromedriver"); // And now use this to visit Google driver.get("http://www.google.com"); // Alternatively the same thing can be done like this // driver.navigate().to("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();//www.j av a2s . com // Check the title of the page System.out.println("Page title is: " + driver.getTitle()); // Google's search is rendered dynamically with JavaScript. // Wait for the page to load, timeout after 10 seconds (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("cheese!"); } }); // Should see: "cheese! - Google Search" System.out.println("Page title is: " + driver.getTitle()); //Close the browser driver.quit(); }