List of usage examples for org.openqa.selenium.interactions Actions Actions
public Actions(WebDriver driver)
From source file:cat.calidos.morfeu.webapp.ui.UIWidget.java
License:Apache License
@SuppressWarnings("unchecked") public T pressKey(String k) { // we are sending the keys this way as it seems to work as it should, selenide or selenium has a lot of trouble here Actions actions = new Actions(driver); //actions.moveToElement(element.getWrappedElement()); //actions.click(); actions.sendKeys(Keys.chord((CharSequence) k)); actions.build().perform();/* w w w .java 2s. c o m*/ // this keeps failing randomly try { Thread.sleep(50); } catch (InterruptedException e) { } return (T) this; }
From source file:cat.calidos.morfeu.webapp.ui.UIWidget.java
License:Apache License
@SuppressWarnings("unchecked") public T pressBackspace() { WebDriver driver = element.getWrappedDriver(); Actions actions = new Actions(driver); actions.sendKeys(Keys.BACK_SPACE);//from w w w.j av a 2 s. co m actions.build().perform(); return (T) this; }
From source file:cc.kune.selenium.SeleniumUtils.java
License:GNU Affero Public License
/** * Double click.//from ww w .ja va 2s . c o m * * @param webdriver * the webdriver * @param element * the element */ public static void doubleClick(final WebDriver webdriver, final WebElement element) { SeleniumUtils.moveMouseTo(webdriver, element); sleep(300); SeleniumUtils.hightlight(element, webdriver); final Actions builder = new Actions(webdriver); final Action doubleClick = builder.doubleClick(element).build(); doubleClick.perform(); }
From source file:cc.kune.selenium.SeleniumUtils.java
License:GNU Affero Public License
/** * Move mouse to.//from www .j a v a 2s. c o m * * @param webdriver * the webdriver * @param element * the element */ public static void moveMouseTo(final WebDriver webdriver, final WebElement element) { SeleniumUtils.showCursor(webdriver, element); final Actions builder = new Actions(webdriver); final Action action = builder.moveToElement(element).build(); action.perform(); }
From source file:cc.kune.selenium.SeleniumUtils.java
License:GNU Affero Public License
/** * Move mouse to./*from ww w.j a v a2 s .c o m*/ * * @param webdriver * the webdriver * @param element * the element * @param xOffset * the x offset * @param yOffset * the y offset */ public static void moveMouseTo(final WebDriver webdriver, final WebElement element, final int xOffset, final int yOffset) { showCursor(webdriver, element, xOffset, yOffset); final Actions actions = new Actions(webdriver); actions.moveToElement(element, xOffset, yOffset); final Action action = actions.build(); action.perform(); }
From source file:cc.kune.selenium.SeleniumUtils.java
License:GNU Affero Public License
/** * Move mouse to and click.// w ww. j a va 2s .c o m * * @param webdriver * the webdriver * @param element * the element * @param xOffset * the x offset * @param yOffset * the y offset */ public static void moveMouseToAndClick(final WebDriver webdriver, final WebElement element, final int xOffset, final int yOffset) { // showCursor(webdriver, element, xOffset, yOffset); final Actions actions = new Actions(webdriver); actions.moveToElement(element, xOffset, yOffset); actions.click(); final Action action = actions.build(); action.perform(); }
From source file:ch.vorburger.vaadin.designer.tests.web.DesignerWebDriverTest.java
License:Apache License
@BeforeClass public static void setUpClass() throws Exception { // This is needed (only) for stand-alone EMF initialization SamplescreenPackage.eINSTANCE.eClass(); final String path = "/ch/vorburger/vaadin/designer/samplescreen/screen1.xmi"; URL url = DesignerWebDriverTest.class.getResource(path); if (url == null) throw new IOException("Could not getResource() for " + path); screen = new EIO().load(URI.createURI(url.toString()), Screen.class); driver = newWebDriver();/* w w w . ja v a2 s. c o m*/ wait = new WebDriverWait(driver, 10); action = new Actions(driver); server = new DesignerServer(); server.start(); root = new SampleFixedScreenComponent(); new SampleFixedScreenBinding().bind(root, screen); server.getDesignerApplication().setRootContent(root); driver.get(server.getURL()); wait.until(ExpectedConditions.elementToBeClickable(By.id("name"))); }
From source file:cn.edu.hfut.dmic.webcollector.example.FirefoxSelenium3.java
License:Open Source License
public static void main(String[] args) throws Exception { Executor executor = new Executor() { @Override//from w w w.j a v a 2 s. 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("attend_rate")) { db.getCollection(s).drop(); } } DBCollection dbCollection = db.getCollection("attend_rate"); ProfilesIni pi = new ProfilesIni(); FirefoxProfile profile = pi.getProfile("default"); WebDriver driver = new FirefoxDriver(profile); driver.manage().window().maximize(); driver.manage().timeouts().pageLoadTimeout(3, TimeUnit.SECONDS); // driver.setJavascriptEnabled(false); driver.get(datum.getUrl()); // System.out.println(driver.getPageSource()); driver.findElement(By.xpath("//*[@id='seat_city']")).click(); driver.switchTo().window(driver.getWindowHandle()); int city_num = driver.findElements(By.xpath("//div[@id='all-citys']/div/ul/li/a")).size(); for (int i = 0; i < city_num; i++) { System.out.println("A city chosen" + i); System.out.println( driver.findElements(By.xpath("//div[@id='all-citys']/div/ul/li/a")).get(i).getText()); String city = driver.findElements(By.xpath("//div[@id='all-citys']/div/ul/li/a")).get(i) .getText(); ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", driver.findElements(By.xpath("//div[@id='all-citys']/div/ul/li/a")).get(i)); ((JavascriptExecutor) driver).executeScript("window.scrollBy(0, -250)", ""); Thread.sleep(1000); new Actions(driver) .moveToElement( driver.findElements(By.xpath("//div[@id='all-citys']/div/ul/li/a")).get(i)) .click().perform(); driver.switchTo().window(driver.getWindowHandle()); // System.out.println(driver.findElement(By.xpath("//span[@class='today']/em")).getText()); System.out.println(driver.findElement(By.xpath("//span[@class='today']")).getText()); for (int j = 0; j < driver .findElements(By.xpath("//div[@id='seat_table']//ul//li[@class='c1 lineDot']")) .size(); j++) { System.out.println(driver .findElements(By.xpath("//div[@id='seat_table']//ul//li[@class='c1 lineDot']")) .get(j).getText()); System.out.println( driver.findElements(By.xpath("//div[@id='seat_table']//ul//li[@class='c2 red']")) .get(j).getText()); System.out.println( driver.findElements(By.xpath("//div[@id='seat_table']//ul//li[@class='c3 gray']")) .get(j).getText()); BasicDBObject dbObject = new BasicDBObject(); dbObject.append("title", driver.findElement(By.xpath("//span[@class='today']")).getText()) .append("city", city) .append("mov_cnname", driver.findElements( By.xpath("//div[@id='seat_table']//ul//li[@class='c1 lineDot']")) .get(j).getText()) .append("boxoffice_rate", driver .findElements(By.xpath("//div[@id='seat_table']//ul//li[@class='c2 red']")) .get(j).getText()) .append("visit_pershow", driver .findElements(By.xpath("//div[@id='seat_table']//ul//li[@class='c3 gray']")) .get(j).getText()); dbCollection.insert(dbObject); } System.out.println("new city list to choose"); new Actions(driver).moveToElement(driver.findElement(By.xpath("//*[@id='seat_city']"))).click() .perform(); driver.switchTo().window(driver.getWindowHandle()); Thread.sleep(500); } driver.close(); driver.quit(); mongoClient.close(); } }; //DBDBManager DBManager manager = new BerkeleyDBManager("crawl"); //Crawler?DBManagerExecutor Crawler crawler = new Crawler(manager, executor); crawler.addSeed("http://pf.maoyan.com/attend/rate"); crawler.start(1); }
From source file:com.ataco.erzeta.TC_RZ_1.java
/** * TC-RZ-3 (hlavn)//from w w w. j av a 2 s . com * Test na vytvoen nov rezervace. */ @Test public void testAddNewReservation() { clickPlusButton(); NativeSelectElement sourceSelect = $(NativeSelectElement.class).first(); sourceSelect.selectByText(testedSourceName); Calendar c = Calendar.getInstance(); c.setTime(new Date()); c.add(Calendar.DATE, 2); int day = c.get(Calendar.DAY_OF_MONTH); TestBenchElement datepicker = (TestBenchElement) findElements( By.cssSelector(".v-touchkit-datepicker-datePickerDetailView")).get(1); datepicker.focus(); datepicker.click(); Actions actions = new Actions(getDriver()); actions.sendKeys(Integer.toString(day)); actions.build().perform(); SliderElement slider1 = $(SliderElement.class).first(); slider1.click(); actions = new Actions(getDriver()); for (int i = 1; i < quantity; i++) { actions.sendKeys(Keys.ARROW_RIGHT); } actions.build().perform(); TextAreaElement descriptionTextArea = $(TextAreaElement.class).caption("Popis:").first(); descriptionTextArea.setValue(testedDescription); ButtonElement saveButton = $(ButtonElement.class).caption("ULOIT").first(); saveButton.click(); sleep(500); testDataFromNewReservation(); }
From source file:com.ataco.erzeta.TC_RZ_3.java
/** * TC-RZ-3 (hlavn)// ww w .j av a 2 s . c o m * Test na vytvoen novho zdroje */ @Test public void testAddNewSource() { NativeButtonElement menuButton = $(NativeButtonElement.class).caption("").first(); menuButton.click(); sleep(500); NativeButtonElement sourcesButton = $(NativeButtonElement.class).caption("Zdroje").first(); sourcesButton.click(); sleep(500); clickPlusButton(); sleep(500); TextFieldElement nameLabel = $(TextFieldElement.class).caption("Nzev").first(); nameLabel.setValue(testedSourceName); Calendar c = Calendar.getInstance(); c.setTime(new Date()); TestBenchElement existSince = (TestBenchElement) findElements(By.cssSelector(".v-touchkit-datepicker")) .get(0); existSince.focus(); existSince.click(); String sequence = String.format( "%s" + Integer.toString(c.get(Calendar.DAY_OF_MONTH)) + "%s" + Integer.toString(c.get(Calendar.MONTH)) + Integer.toString(c.get(Calendar.YEAR)), c.get(Calendar.DAY_OF_MONTH) < 10 ? "0" : "", c.get(Calendar.MONTH) < 10 ? "0" : ""); Actions actions = new Actions(getDriver()); actions.sendKeys(sequence); actions.build().perform(); TestBenchElement existTill = (TestBenchElement) findElements(By.cssSelector(".v-touchkit-datepicker")) .get(1); existTill.focus(); existTill.click(); actions = new Actions(getDriver()); c.add(Calendar.DATE, 2); sequence = String.format( "%s" + Integer.toString(c.get(Calendar.DAY_OF_MONTH)) + "%s" + Integer.toString(c.get(Calendar.MONTH)) + Integer.toString(c.get(Calendar.YEAR)), c.get(Calendar.DAY_OF_MONTH) < 10 ? "0" : "", c.get(Calendar.MONTH) < 10 ? "0" : ""); actions.sendKeys(sequence); actions.build().perform(); TextFieldElement capacityTextField = $(TextFieldElement.class).caption("Kapacita").first(); capacityTextField.setValue(Integer.toString(capacity)); TestBenchElement publicAccessSwitch = (TestBenchElement) findElement(By.cssSelector(".v-touchkit-switch")); publicAccessSwitch.click(); sleep(100); TextAreaElement descriptionTextArea = $(TextAreaElement.class).caption("Popis").first(); descriptionTextArea.setValue(testedDescription); TestBenchElement authorizationsTab = (TestBenchElement) findElements(By.cssSelector(".v-tabsheet-tabitem")) .get(1); authorizationsTab.click(); clickPlusButton(); NativeSelectElement usernameSelect = $(NativeSelectElement.class).first(); usernameSelect.selectByText("testovaciJmeno testovaciPrijmeni"); NativeButtonElement saveButton = $(NativeButtonElement.class).caption("ULOIT").first(); saveButton.click(); sleep(500); testDataFromNewReservation(); }