List of usage examples for org.openqa.selenium WebElement getSize
Dimension getSize();
From source file:akori.AKORI.java
public static void main(String[] args) throws IOException, InterruptedException { System.out.println("esto es AKORI"); URL = "http://www.mbauchile.cl"; PATH = "E:\\NetBeansProjects\\AKORI\\"; NAME = "mbauchile.png"; // Extrar DOM tree Document doc = Jsoup.connect(URL).timeout(0).get(); // The Firefox driver supports javascript WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); System.out.println(driver.manage().window().getSize().toString()); System.out.println(driver.manage().window().getPosition().toString()); int xmax = driver.manage().window().getSize().width; int ymax = driver.manage().window().getSize().height; // Go to the URL page driver.get(URL);/* www. ja va 2s . com*/ File screen = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screen, new File(PATH + NAME)); BufferedImage img = ImageIO.read(new File(PATH + NAME)); //Graphics2D graph = img.createGraphics(); BufferedImage img1 = new BufferedImage(xmax, ymax, BufferedImage.TYPE_INT_ARGB); Graphics2D graph1 = img.createGraphics(); double[][] matrix = new double[ymax][xmax]; BufferedReader in = new BufferedReader(new FileReader("et.txt")); String linea; double max = 0; graph1.drawImage(img, 0, 0, null); HashMap<String, Integer> lista = new HashMap<String, Integer>(); int count = 0; for (int i = 0; (linea = in.readLine()) != null && i < 10000; ++i) { String[] datos = linea.split(","); int x = (int) Double.parseDouble(datos[0]); int y = (int) Double.parseDouble(datos[2]); long time = Double.valueOf(datos[4]).longValue(); if (x >= xmax || y >= ymax) continue; if (time < 691215) continue; if (time > 705648) break; if (lista.containsKey(x + "," + y)) lista.put(x + "," + y, lista.get(x + "," + y) + 1); else lista.put(x + "," + y, 1); ++count; } System.out.println(count); in.close(); Iterator iter = lista.entrySet().iterator(); Map.Entry e; for (String key : lista.keySet()) { Integer i = lista.get(key); if (max < i) max = i; } System.out.println(max); max = 0; while (iter.hasNext()) { e = (Map.Entry) iter.next(); String xy = (String) e.getKey(); String[] datos = xy.split(","); int x = Integer.parseInt(datos[0]); int y = Integer.parseInt(datos[1]); matrix[y][x] += (int) e.getValue(); double aux; if ((aux = normalMatrix(matrix, y, x, ((int) e.getValue()) * 4)) > max) { max = aux; } //normalMatrix(matrix,x,y,20); if (matrix[y][x] > max) max = matrix[y][x]; } int A, R, G, B, n; for (int i = 0; i < xmax; ++i) { for (int j = 0; j < ymax; ++j) { if (matrix[j][i] != 0) { n = (int) Math.round(matrix[j][i] * 100 / max); R = Math.round((255 * n) / 100); G = Math.round((255 * (100 - n)) / 100); B = 0; A = Math.round((255 * n) / 100); ; if (R > 255) R = 255; if (R < 0) R = 0; if (G > 255) G = 255; if (G < 0) G = 0; if (R < 50) A = 0; graph1.setColor(new Color(R, G, B, A)); graph1.fillOval(i, j, 1, 1); } } } //graph1.dispose(); ImageIO.write(img, "png", new File("example.png")); System.out.println(max); graph1.setColor(Color.RED); // Extraer elementos Elements e1 = doc.body().getAllElements(); int i = 1; ArrayList<String> tags = new ArrayList<String>(); for (Element temp : e1) { if (tags.indexOf(temp.tagName()) == -1) { tags.add(temp.tagName()); List<WebElement> query = driver.findElements(By.tagName(temp.tagName())); for (WebElement temp1 : query) { Point po = temp1.getLocation(); Dimension d = temp1.getSize(); if (d.width <= 0 || d.height <= 0 || po.x < 0 || po.y < 0) continue; System.out.println(i + " " + temp.nodeName()); System.out.println(" x: " + po.x + " y: " + po.y); System.out.println(" width: " + d.width + " height: " + d.height); graph1.draw(new Rectangle(po.x, po.y, d.width, d.height)); ++i; } } } graph1.dispose(); ImageIO.write(img, "png", new File(PATH + NAME)); driver.quit(); }
From source file:akori.DrawLevel.java
public static void processSelenideElement(SelenideElement elem, Element temp, Integer id) { // System.out.println("Examining selenide element '" + elem + "'"); WebElement temp1 = elem.toWebElement(); Point po = temp1.getLocation(); Dimension d = temp1.getSize(); if (d.width <= 0 || d.height <= 0 || po.x < 0 || po.y < 0) { return;/*from ww w . java2 s. c om*/ } int dep = 0; int j = 1; for (; !elem.equals(s); ++j) { elem = elem.parent(); if (j > MAX_DEPTH) { break; } } Integer k = 0; String str = ""; if (temp.hasText()) { str = temp.nodeName() + "," + po.x + "," + po.y + "," + d.width + "," + d.height + "," + j + "," + 1 + "," + id + "," + (k + 1); } else { str = temp.nodeName() + "," + po.x + "," + po.y + "," + d.width + "," + d.height + "," + j + "," + 0 + "," + id + "," + (k + 1); } elements.add(str); if (j > maxj) { maxj = j; } }
From source file:akori.Features.java
public static void main(String[] args) throws IOException, InterruptedException { URL = "http://www.mbauchile.cl"; Document doc = Jsoup.connect(URL).timeout(0).get(); WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get(URL);/* w ww . j a v a 2 s . c om*/ Elements e1 = doc.body().getAllElements(); Element e = doc.body(); PrintWriter writer = new PrintWriter("features.txt", "UTF-8"); int i = 1; // String[][] matrix = new String[e1.size()][10]; // traverse(e, 1, 1, "", 1, writer, driver); ArrayList<String> tags = new ArrayList<String>(); System.out.println(""); // for (Element temp : e1) { // if (!temp.nodeName().equals("br")) { // writer.println(i + "," + temp.hashCode() + "," + temp.nodeName() + "," + temp.id()); // //System.out.println(i+","+temp.hashCode()+","+temp.nodeName()); // ++i; // } // } i = 1; for (Element temp : e1) { if (tags.indexOf(temp.tagName()) == -1) { tags.add(temp.tagName()); List<WebElement> query = driver.findElements(By.tagName(temp.tagName())); for (WebElement temp1 : query) { Point po = temp1.getLocation(); Dimension d = temp1.getSize(); if (d.width <= 0 || d.height <= 0 || po.x < 0 || po.y < 0) { continue; } if (temp1.getTagName().equals("img")) writer.println(i + "," + temp1.getTagName() + "," + po.x + "," + po.y + "," + d.width + "," + d.height + "," + temp1.getAttribute("class") + "," + temp1.getAttribute("src")); else if (temp1.getTagName().equals("a")) writer.println(i + "," + temp1.getTagName() + "," + po.x + "," + po.y + "," + d.width + "," + d.height + "," + temp1.getAttribute("class") + "," + temp1.getAttribute("href")); else writer.println(i + "," + temp1.getTagName() + "," + po.x + "," + po.y + "," + d.width + "," + d.height + "," + temp1.getAttribute("class") + "," + temp1.getText()); ++i; } } } driver.quit(); writer.close(); }
From source file:akori.Features.java
public static void traverse(Element e, int level, int index, String xpath, int siblings, PrintWriter writer, WebDriver driver) {// w ww .j a v a2s .c o m if (siblings > 1) { WebElement webe = null; try { webe = driver.findElement(By.xpath("/" + xpath + "/" + e.nodeName() + "[" + index + "]")); } catch (Exception exp) { System.out.println("exception no se encontro"); } if (webe != null) { Point po = webe.getLocation(); Dimension d = webe.getSize(); if (d.width <= 0 || d.height <= 0 || po.x < 0 || po.y < 0) { System.out.println("elemento negativo"); } else { writer.println("/" + xpath + "/" + e.nodeName() + "[" + index + "]," + e.nodeName() + "," + po.x + "," + po.y + "," + d.width + "," + d.height + "," + level); } } } else { WebElement webe = null; try { webe = driver.findElement(By.xpath("/" + xpath + "/" + e.nodeName())); } catch (Exception exp) { System.out.println("exception no se encontro"); } if (webe != null) { Point po = webe.getLocation(); Dimension d = webe.getSize(); if (d.width <= 0 || d.height <= 0 || po.x < 0 || po.y < 0) { System.out.println("elemento negativo"); } else { writer.println("/" + xpath + "/" + e.nodeName() + "," + e.nodeName() + "," + po.x + "," + po.y + "," + d.width + "," + d.height + "," + level); } } } int childSize = e.children().size(); Elements children = e.children(); int i = 1; for (Element temp : children) { if (siblings > 1) { traverse(temp, level + 1, i, xpath + "/" + e.nodeName() + "[" + index + "]", childSize, writer, driver); } else { traverse(temp, level + 1, i, xpath + "/" + e.nodeName(), childSize, writer, driver); } ++i; } }
From source file:akori.FeaturesSelenide.java
public static void main(String[] args) throws Exception { System.out.println("esto es FeaturesSelenide"); PrintWriter writer = new PrintWriter("features.txt", "UTF-8"); try {//from w ww . j ava2s . c om String URL = "http://www.mbauchile.cl"; open(URL); SelenideElement s = $(By.tagName("body")); Document doc = Jsoup.connect(URL).timeout(0).get(); Elements e1 = doc.body().getAllElements(); ArrayList<String> tags = new ArrayList<String>(); int i = 1; for (Element temp : e1) { if (tags.indexOf(temp.tagName()) == -1) { tags.add(temp.tagName()); ElementsCollection query = $$(By.tagName(temp.tagName())); for (SelenideElement temp2 : query) { WebElement temp1 = temp2.toWebElement(); Point po = temp1.getLocation(); Dimension d = temp1.getSize(); if (d.width <= 0 || d.height <= 0 || po.x < 0 || po.y < 0) { continue; } if (temp1.getTagName().equals("img")) { writer.print(i + "," + temp1.getTagName() + "," + po.x + "," + po.y + "," + d.width + "," + d.height + "," + temp1.getAttribute("class") + "," + temp1.getAttribute("src")); int j = 1; for (j = 1; !temp2.equals(s); ++j) { temp2 = temp2.parent(); if (j > 100) break; } writer.println("," + j); } else if (temp1.getTagName().equals("a")) { writer.println(i + "," + temp1.getTagName() + "," + po.x + "," + po.y + "," + d.width + "," + d.height + "," + temp1.getAttribute("class") + "," + temp1.getAttribute("href")); int j = 1; for (j = 1; !temp2.equals(s); ++j) { temp2 = temp2.parent(); if (j > 100) break; } writer.println("," + j); } else { writer.println(i + "," + temp1.getTagName() + "," + po.x + "," + po.y + "," + d.width + "," + d.height + "," + temp1.getAttribute("class") + "," + temp1.getText()); int j = 1; for (j = 1; !temp2.equals(s); ++j) { temp2 = temp2.parent(); if (j > 100) break; } writer.println("," + j); } ++i; } } } } catch (Exception e) { e.printStackTrace(); } writer.close(); }
From source file:akori.SELENIUM.java
public static void main(String[] args) throws Exception { // The Firefox driver supports javascript WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); System.out.println(driver.manage().window().getSize().toString()); System.out.println(driver.manage().window().getPosition().toString()); URL = "http://www.mbauchile.cl"; PATH = "E:\\NetBeansProjects\\AKORI\\1.png"; // Go to the Google Suggest home page driver.get(URL);//w ww . j a v a2 s . c om // Enter the query string "Cheese" WebElement query = driver.findElement(By.id("container")); Point p = query.getLocation(); Dimension d = query.getSize(); System.out.println("x: " + p.x + " y: " + p.y); System.out.println("width: " + d.width + " height: " + d.height); driver.quit(); }
From source file:br.ufmg.dcc.saotome.beholder.selenium.WebElementAdapter.java
License:Apache License
@Override public Dimension getSize() { return new StaleExceptionResolver<Dimension>() { @Override//from w ww. jav a2 s. c o m public Dimension execute(WebElement element) { return element.getSize(); } }.waitForElement(); }
From source file:com.assertthat.selenium_shutterbug.utils.web.Coordinates.java
License:Open Source License
public Coordinates(WebElement element) { Point point = element.getLocation(); Dimension size = element.getSize(); this.width = size.getWidth(); this.height = size.getHeight(); this.x = point.getX(); this.y = point.getY(); }
From source file:com.checkAuto.appium.screens.nativeapp.makemytrip.CopyOfGenerate_orders.java
public void into() throws InterruptedException { Thread.sleep(3000);/* w w w. j a v a 2 s. com*/ login_button.click(); Thread.sleep(5000); new_add_detection.click(); // Thread.sleep(5000); // index1.click(); // choose_confirm.click(); /*edit_search.sendKeys("?"); search_button.click(); search_index1.click(); confirm_yes.click();*/ // ? ? basic_info.click(); /*car_num_area_list.click(); car_num_area_list_index.click(); car_num.sendKeys("LYN100"); // car_type_box.click(); car_type.click(); // car_publiser_.click(); //? firsthand_n.click(); // transfer_user_y.click(); // transfer_date.click(); confirm_yes.click(); // transfer_times_input.click(); transfer_times.click(); // using_nature_.click(); using_nature_index.click(); //VIN vin_code_.sendKeys("LYW091"); // models_cars.click(); models_cars_1.click(); models_cars_1_2.click(); models_cars_1_2_3.click(); //? guobiao_num.sendKeys("LYW000001"); Thread.sleep(2000);*/ //? // driver.scrollTo(""); int width = driver.manage().window().getSize().width; int height = driver.manage().window().getSize().height; driver.swipe(width / 2, height * 6 / 10, width / 2, height / 10, 1000); // Thread.sleep(2000); // /* production_date.click(); confirm_yes.click(); //?? engine_num.sendKeys("LYW0000001"); // register_date.click(); confirm_yes.click(); // jiaoqiangxian_n.click(); // commercial_insurance_n.click(); // nianjian_n.click(); // travel_tax_n.click();*/ driver.swipe(width / 2, height * 6 / 10, width / 2, height / 10, 1000); // car_inventory_input.click(); /*car_inventory_province.click(); car_inventory_province_index.click(); car_inventory_city.click(); car_inventory_city_index.click(); confirm_yes.click();*/ WebElement ee = driver.findElementById("com.youxinpai.checkauto.act:id/sd_sidebar"); //?left,top Point p1 = ee.getLocation(); //? int w1 = ee.getSize().width; //? int h1 = ee.getSize().height; //bounds ?p1.x, p1.y?p1.x+w1, p1.y+h1 //Rect r = new Rect(p1.x, p1.y, p1.x+w1, p1.y+h1); //Rect r = new Rect(int left, int top, int right, int bottom) UIAUTOMATOR? // bottom-top int h2 = p1.y + h1 - p1.y; //22?22?? int h3 = h2 / 22; // X?? // public final float exactCenterX() { // return (left + right) * 0.5f; // } //Y?? // public final int centerY() { // return (top + bottom) >> 1; // } //x???? int x = (p1.x + p1.x + w1) >> 1; //Y??top + bottom //????? int y = 0; for (int n = 0; n < 22; n++) { y = ((p1.y + (n * h3)) + (p1.y + h1 - ((22 - n) * h3))) >> 1; driver.tap(1, x, y, 500); } driver.tap(1, x, y, 500); // driver.tap(1, x,y,500); // // driver.tap(1, x,y,500); // System.out.println(ee.getText()); // System.out.println(ee.getAttribute("index")); System.out.println("------"); /* Point p=ee.getLocation(); System.out.println(p.x); System.out.println(p.y); Thread.sleep(10000); ee.click();*/ Thread.sleep(15000); TouchAction act = new TouchAction(driver); act.longPress(1035, 251).moveTo(1035, 1873).release().perform(); // WebElement datePicker= driver.findElement(By.name("Date Picker")); // WebElement steppers= driver.findElement(By.name("Steppers")); int startY = ee.getLocation().y; int endY = ee.getLocation().y; System.out.println(startY + " -- " + endY); Thread.sleep(10000); //act.press(datePicker, 30, 10).release().perform(); //act.press(150, startY).moveTo(150, endY).release().perform(); //act.press(ee, 30, 10).moveTo(act).release().perform(); // ee. // obj = deriver.findByid("A"); // Rect r = obj.getBounds(); // // // int h = r.height(); // // //? // int h1 = h/22; // // // ?? // Rect r1 = new Rect(1062,225+(2*h1),1152,1776-((22-2)*h1)); // device.click(r1.centerX(),r1.centerY()); // choose_car_color.click(); choose_white_color.click(); // fuel_type.click(); choose_electric.click(); /*int w = driver.manage().window().getSize().width; int h = driver.manage().window().getSize().height; driver.swipe(w/2, h*6/10, w/2, h/10, 1000);*/ displacement1.click(); displacement1_index.click(); displacement2.click(); displacement2_index.click(); // driver.scrollTo("??"); // car_key.click(); //2 car_key_2.click(); save_info.click(); // // // // // // // // // // // // // using_nature_box.click(); // using_nature.click(); }
From source file:com.checkAuto.appium.screens.nativeapp.makemytrip.Copy_2_of_Generate_orders.java
public void into() throws InterruptedException { Thread.sleep(3000);//from w w w .j a va 2 s .c om login_button.click(); Thread.sleep(5000); new_add_detection.click(); // Thread.sleep(5000); // index1.click(); // choose_confirm.click(); /*edit_search.sendKeys("?"); search_button.click(); search_index1.click(); confirm_yes.click();*/ // ? ? basic_info.click(); /*car_num_area_list.click(); car_num_area_list_index.click(); car_num.sendKeys("LYN100"); // car_type_box.click(); car_type.click(); // car_publiser_.click(); //? firsthand_n.click(); // transfer_user_y.click(); // transfer_date.click(); confirm_yes.click(); // transfer_times_input.click(); transfer_times.click(); // using_nature_.click(); using_nature_index.click(); //VIN vin_code_.sendKeys("LYW091"); // models_cars.click(); models_cars_1.click(); models_cars_1_2.click(); models_cars_1_2_3.click(); //? guobiao_num.sendKeys("LYW000001"); Thread.sleep(2000);*/ //? // driver.scrollTo(""); int width = driver.manage().window().getSize().width; int height = driver.manage().window().getSize().height; driver.swipe(width / 2, height * 6 / 10, width / 2, height / 10, 1000); // Thread.sleep(2000); // /* production_date.click(); confirm_yes.click(); //?? engine_num.sendKeys("LYW0000001"); // register_date.click(); confirm_yes.click(); // jiaoqiangxian_n.click(); // commercial_insurance_n.click(); // nianjian_n.click(); // travel_tax_n.click();*/ driver.swipe(width / 2, height * 6 / 10, width / 2, height / 10, 1000); // car_inventory_input.click(); /*car_inventory_province.click(); car_inventory_province_index.click(); car_inventory_city.click(); car_inventory_city_index.click(); confirm_yes.click();*/ WebElement ee = driver.findElementById("com.youxinpai.checkauto.act:id/sd_sidebar"); //?left,top Point p1 = ee.getLocation(); //? int w1 = ee.getSize().width; //? int h1 = ee.getSize().height; //bounds ?p1.x, p1.y?p1.x+w1, p1.y+h1 //Rect r = new Rect(p1.x, p1.y, p1.x+w1, p1.y+h1); //Rect r = new Rect(int left, int top, int right, int bottom) UIAUTOMATOR? // bottom-top int h2 = p1.y + h1 - p1.y; //22?22?? int h3 = h2 / 22; // X?? // public final float exactCenterX() { // return (left + right) * 0.5f; // } //Y?? // public final int centerY() { // return (top + bottom) >> 1; // } //x???? int x = (p1.x + p1.x + w1) >> 1; //Y??top + bottom //????? int y = 0; for (int n = 0; n < 3; n++) { y = ((p1.y + (n * h3)) + (p1.y + h1 - ((22 - n) * h3))) >> 1; driver.tap(1, x, y, 500); } driver.tap(1, x, y, 500); // driver.tap(1, x,y,500); // // driver.tap(1, x,y,500); // System.out.println(ee.getText()); // System.out.println(ee.getAttribute("index")); System.out.println("------"); /* Point p=ee.getLocation(); System.out.println(p.x); System.out.println(p.y); Thread.sleep(10000); ee.click();*/ Thread.sleep(15000); TouchAction act = new TouchAction(driver); act.longPress(1035, 251).moveTo(1035, 1873).release().perform(); act.longPress(1035, 251).moveTo(1035, 1873).release().perform(); act.longPress(1035, 251).moveTo(1035, 1873).release().perform(); act.longPress(1035, 251).moveTo(1035, 1873).release().perform(); act.longPress(1035, 251).moveTo(1035, 1873).release().perform(); // WebElement datePicker= driver.findElement(By.name("Date Picker")); // WebElement steppers= driver.findElement(By.name("Steppers")); int startY = ee.getLocation().y; int endY = ee.getLocation().y; System.out.println(startY + " -- " + endY); Thread.sleep(10000); //act.press(datePicker, 30, 10).release().perform(); //act.press(150, startY).moveTo(150, endY).release().perform(); //act.press(ee, 30, 10).moveTo(act).release().perform(); // ee. // obj = deriver.findByid("A"); // Rect r = obj.getBounds(); // // // int h = r.height(); // // //? // int h1 = h/22; // // // ?? // Rect r1 = new Rect(1062,225+(2*h1),1152,1776-((22-2)*h1)); // device.click(r1.centerX(),r1.centerY()); // choose_car_color.click(); choose_white_color.click(); // fuel_type.click(); choose_electric.click(); /*int w = driver.manage().window().getSize().width; int h = driver.manage().window().getSize().height; driver.swipe(w/2, h*6/10, w/2, h/10, 1000);*/ displacement1.click(); displacement1_index.click(); displacement2.click(); displacement2_index.click(); // driver.scrollTo("??"); // car_key.click(); //2 car_key_2.click(); save_info.click(); // // // // // // // // // // // // // using_nature_box.click(); // using_nature.click(); }