List of usage examples for org.openqa.selenium.interactions Actions keyDown
public Actions keyDown(CharSequence key)
From source file:StoryKeyboardShortcutTests.java
@Test public void storyKeyDelete() throws InterruptedException { //a. Launch story in firefox driver.get(//from w ww . j a v a 2s. c o m "http://tanveer-pc:9724/web/story/story.html?debug&storyhub=tanveer-pc&gh=Guest/@tanveer-pc&pilot=tanveer-pc&preview=tanveer-pc&mediaservice=tanveer-pc"); //driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); WebDriverWait wait = new WebDriverWait(driver, 15); wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector( "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']"))); //Close the license popup WebElement okButton = driver.findElement(By.cssSelector( "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']")); okButton.click(); //Click on Media tab WebElement uploadButton = driver.findElement( By.xpath("html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[1]/div[1]/div/table/tbody/tr/td")); uploadButton.click(); //From storytab double click on story named 'storytest' Thread.sleep(2000); WebElement storytest = driver.findElement(By.xpath( "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div/div[3]")); storytest.click(); WebElement storytest1 = driver.findElement(By.xpath( "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div/div[3]")); storytest1.click(); storytest1.click(); Thread.sleep(3000); //Select the video element in timeline div[class="thumbnailStrip"] WebElement timelinebar = driver.findElement(By.cssSelector("div[class='thumbnailStrip']")); timelinebar.click(); Thread.sleep(2000); WebElement timebarnumber = driver.findElement( By.xpath("//div[contains(@style,'POSITION') and @eventproxy='sta_timeline_cursorlabel_1']")); final String timevalue = timebarnumber.getText(); WebElement timebarnumber1 = driver.findElement( By.xpath("//div[contains(@style,'POSITION') and @eventproxy='sta_timeline_cursorlabel_1']")); final String timevalue1 = timebarnumber.getText(); Actions action = new Actions(driver); //Asserting if presence of element shows false after deletion button is pressed action.sendKeys(Keys.DELETE).build().perform(); Boolean isPresent2 = driver.findElements(By.cssSelector("div[class='thumbnailStrip']")).size() > 0; Assert.assertEquals(false, isPresent2); // Undoing the change to timeline by pressing 'CTRL + Z' Thread.sleep(2000); Actions action2 = new Actions(driver); action2.keyDown(Keys.CONTROL).sendKeys(String.valueOf('\u007A')).perform(); /* Thread.sleep(2000); Actions action = new Actions(driver); //String selectAll = Keys.chord(Keys.CONTROL, "a"); action.sendKeys(".").perform(); // action.sendKeys(selectAll).build().perform(); //action.sendKeys(Keys.getKeyFromUnicode('selectAll')).build().perform(); */ }
From source file:be.rubus.web.testing.AbstractWidget.java
License:Apache License
protected void click(WebElement element, Keys... keys) { Actions builder = new Actions(driver); for (Keys key : keys) { builder.keyDown(key); }//from w ww . j a v a 2 s .c o m builder.click(element); for (Keys key : keys) { builder.keyUp(key); } Action action = builder.build(); action.perform(); }
From source file:com.consol.citrus.selenium.actions.DropDownSelectAction.java
License:Apache License
@Override protected void execute(WebElement webElement, SeleniumBrowser browser, TestContext context) { super.execute(webElement, browser, context); Select dropdown = new Select(webElement); if (StringUtils.hasText(option)) { dropdown.selectByValue(context.replaceDynamicContentInString(option)); }// w ww . j ava 2 s .com if (!CollectionUtils.isEmpty(options)) { if (BrowserType.IE.equals(browser.getEndpointConfiguration().getBrowserType())) { for (String option : options) { dropdown.selectByValue(context.replaceDynamicContentInString(option)); } } else { List<WebElement> optionElements = dropdown.getOptions(); Actions builder = new Actions(browser.getWebDriver()); builder.keyDown(Keys.CONTROL); for (String optionValue : options) { for (WebElement option : optionElements) { if (!option.isSelected() && isSameValue(option, context.replaceDynamicContentInString(optionValue))) { builder.moveToElement(option).click(option); } } } builder.keyUp(Keys.CONTROL); Action multiple = builder.build(); multiple.perform(); } } }
From source file:com.consol.citrus.selenium.client.WebClient.java
License:Apache License
/** * Select multiple items from a pull-down list. * * @param by// w w w .ja v a2s . c o m * @param from Start at index. * @param to End at index. */ public void selectMultipleItems(By by, int from, int to) { Select dropdown = new Select(findElement(by)); if (BrowserTypeEnum.INTERNET_EXPLORER.equals(browserType)) { for (int i = from; i < to; i++) { dropdown.selectByIndex(i); } } else { //Rest: List<WebElement> options = dropdown.getOptions(); Actions builder = new Actions(webDriver); builder.keyDown(Keys.CONTROL); for (int i = from; i < to; i++) { WebElement item = options.get(i); if (!item.isSelected()) { builder.moveToElement(item).click(item); } } builder.keyUp(Keys.CONTROL); Action multiple = builder.build(); multiple.perform(); } }
From source file:com.digi.selenium.util.common.PageNavigation.java
protected void socialLinks() { try {/*from w w w . j ava 2 s . c o m*/ JavascriptExecutor jse = (JavascriptExecutor) getDriver(); jse.executeScript("window.scrollBy(0,1200)", ""); // WebElement fb = (new WebDriverWait(fbdriver, 5000)).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='main']/section/div/ul/li[1]/a"))); // fb.click(); //*[@id="main"]/section/div/ul/li[1]/a for (int i = 1; i <= 3; i++) { WebElement socialbtn = getDriver() .findElement(By.xpath("//*[@id='main']/section/div/ul/li[" + i + "]/a")); Actions newTab1 = new Actions(getDriver()); newTab1.keyDown(Keys.SHIFT).click(socialbtn).keyUp(Keys.SHIFT).build().perform(); Thread.sleep(500); //handle windows change String base1 = getDriver().getWindowHandle(); Set<String> set1 = getDriver().getWindowHandles(); set1.remove(base1); assert set1.size() == 1; getDriver().switchTo().window((String) set1.toArray()[0]); waitForPageLoad(500); //wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='blueBarNAXAnchor']/div/div/div/div[1]/h1/a/i"))); //close the window getDriver().close(); getDriver().switchTo().window(base1); // handle windows change and switch back to the main window Thread.sleep(500); for (String winHandle1 : getDriver().getWindowHandles()) { getDriver().switchTo().window(winHandle1); System.out.println("Link Validation for :" + socialbtn.getText() + " --> Passed"); log.info("Link Validation for :" + socialbtn.getText() + " --> Passed"); Thread.sleep(500); } } JavascriptExecutor jse1 = (JavascriptExecutor) getDriver(); jse1.executeScript("window.scrollBy(0,-1200)", ""); // jse1.executeScript("window.scrollTo(0,document.body.scrollHeight", ""); Thread.sleep(500); } catch (Exception e) { log.error("Failed to verify Social Media Links shutting down"); shutDown(); } }
From source file:com.digi.selenium.util.PageNavigation.java
protected void extra() { try {// w w w .ja v a 2 s . com JavascriptExecutor jse = (JavascriptExecutor) getDriver(); jse.executeScript("window.scrollBy(0,500)", ""); // WebElement fb = (new WebDriverWait(fbdriver, 5000)).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='main']/section/div/ul/li[1]/a"))); // fb.click(); //*[@id="main"]/section/div/ul/li[1]/a WebElement fb = getDriver().findElement(By.xpath("//*[@id='main']/section/div/ul/li[1]/a")); Actions newTab1 = new Actions(getDriver()); newTab1.keyDown(Keys.SHIFT).click(fb).keyUp(Keys.SHIFT).build().perform(); Thread.sleep(500); //handle windows change String base1 = getDriver().getWindowHandle(); Set<String> set1 = getDriver().getWindowHandles(); set1.remove(base1); assert set1.size() == 1; getDriver().switchTo().window((String) set1.toArray()[0]); waitForPageLoad(500); //wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='blueBarNAXAnchor']/div/div/div/div[1]/h1/a/i"))); //close the window getDriver().close(); getDriver().switchTo().window(base1); // handle windows change and switch back to the main window Thread.sleep(500); for (String winHandle1 : getDriver().getWindowHandles()) { getDriver().switchTo().window(winHandle1); // System.out.println("extra : FB Passed" ); log.info("FB Link Passed"); Thread.sleep(500); //*[@id="main"]/section/div/ul/li[2]/a WebElement tw = getDriver().findElement(By.xpath("//*[@id='main']/section/div/ul/li[2]/a")); Actions newTab2 = new Actions(getDriver()); newTab2.keyDown(Keys.SHIFT).click(tw).keyUp(Keys.SHIFT).build().perform(); Thread.sleep(500); //handle windows change String base2 = getDriver().getWindowHandle(); Set<String> set2 = getDriver().getWindowHandles(); set2.remove(base2); assert set2.size() == 1; getDriver().switchTo().window((String) set2.toArray()[0]); waitForPageLoad(500); //wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='page-container']/div[2]/div/div/div[1]/div/div/div/div[1]/h1/a"))); //close the window getDriver().close(); getDriver().switchTo().window(base2); // handle windows change and switch back to the main window Thread.sleep(2500); for (String winHandle2 : getDriver().getWindowHandles()) { getDriver().switchTo().window(winHandle2); // System.out.println("extra : Twitter Passed" ); log.info("Twitter Link Passed"); Thread.sleep(5000); //*[@id="main"]/section/div/ul/li[3]/a WebElement com = getDriver().findElement(By.xpath("//*[@id='main']/section/div/ul/li[3]/a")); Actions newTab3 = new Actions(getDriver()); newTab3.keyDown(Keys.SHIFT).click(com).keyUp(Keys.SHIFT).build().perform(); Thread.sleep(5000); //handle windows change String base3 = getDriver().getWindowHandle(); Set<String> set3 = getDriver().getWindowHandles(); set3.remove(base3); assert set3.size() == 1; getDriver().switchTo().window((String) set3.toArray()[0]); waitForPageLoad(5000); //wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='mainNav']/div[1]/div[1]/a"))); //close the window getDriver().close(); getDriver().switchTo().window(base3); // handle windows change and switch back to the main window Thread.sleep(2500); for (String winHandle3 : getDriver().getWindowHandles()) { getDriver().switchTo().window(winHandle3); // System.out.println("extra : Community Passed" ); log.info("Community Link Passed"); Thread.sleep(500); JavascriptExecutor jse1 = (JavascriptExecutor) getDriver(); jse1.executeScript("window.scrollBy(0,-500)", ""); } } } } catch (Exception e) { log.error("Failed to verify Social Media Links"); } }
From source file:com.epam.jdi.uitests.mobile.appium.elements.base.Element.java
License:Open Source License
public void clickWithKeys(Keys... keys) { invoker.doJAction("Ctrl click on Element", () -> { Actions action = new Actions(getDriver()); for (Keys key : keys) action = action.keyDown(key); action = action.moveToElement(getWebElement()).click(); for (Keys key : keys) action = action.keyUp(key);/*w w w .j a v a2 s. co m*/ action.perform(); }); }
From source file:com.epam.jdi.uitests.web.selenium.elements.base.Element.java
License:Open Source License
public void clickWithKeys(Keys... keys) { invoker.doJAction("Ctrl click on Element", () -> { Actions action = new Actions(getDriver()); for (Keys key : keys) { action = action.keyDown(key); }//from w ww.j av a 2s . c o m action = action.moveToElement(getWebElement()).click(); for (Keys key : keys) { action = action.keyUp(key); } action.perform(); }); }
From source file:com.ggasoftware.jdi_ui_tests.elements.base.Element.java
License:Open Source License
public void clickWithKeys(Keys... keys) { doJAction("Ctrl click on element", () -> { Actions action = new Actions(getDriver()); for (Keys key : keys) action = action.keyDown(key); action = action.moveToElement(getWebElement()).click(); for (Keys key : keys) action = action.keyUp(key);/* ww w.j av a2 s . c o m*/ action.perform(); }); }
From source file:com.liferay.faces.portal.test.showcase.inputrichtext.InputRichTextTester.java
License:Open Source License
protected static void selectTextAndSendKeys(BrowserDriver browserDriver, String completeText, String textToSelect, CharSequence... keys) { if (!completeText.contains(textToSelect)) { throw new IllegalArgumentException( "\"" + completeText + "\" does not contain \"" + textToSelect + "\""); }/*from www.j a v a 2 s .c o m*/ Actions boldAndItalicize = browserDriver.createActions(BODY_XPATH); WebElement body = browserDriver.findElementByXpath(BODY_XPATH); boldAndItalicize.click(body); for (int i = 0; i < completeText.length(); i++) { boldAndItalicize.sendKeys(Keys.LEFT); } int beginIndex = completeText.indexOf(textToSelect); for (int i = 0; i < beginIndex; i++) { boldAndItalicize.sendKeys(Keys.RIGHT); } boldAndItalicize.keyDown(Keys.SHIFT); for (int i = 0; i < textToSelect.length(); i++) { boldAndItalicize.sendKeys(Keys.RIGHT); } boldAndItalicize.keyUp(Keys.SHIFT); boldAndItalicize.perform(); browserDriver.sendKeysToElement(BODY_XPATH, keys); }