List of usage examples for org.openqa.selenium.interactions Actions moveToElement
public Actions moveToElement(WebElement target)
From source file:com.coderoad.automation.common.util.PageUtil.java
License:Open Source License
/** * Move to element.// w w w. j a v a 2s . com * * @param driver the driver * @param element the element */ public static void moveToElement(final WebDriver driver, final WebElement element) { final Actions builder = new Actions(driver); builder.moveToElement(element); }
From source file:com.coderoad.automation.rocketTruedx.page.LoginPage.java
License:Open Source License
/************************************************************* * @description Login to TRUedx Na //from www . j a v a 2 s. c o m * @return the dealer search page * @throws InterruptedException the interrupted exception *************************************************************/ public MainPage loginToRocketTruedxNa(String user, String password) throws InterruptedException { driver.manage().deleteAllCookies(); this.openPage(TestUtils.getRocketTruedxUrl()); Thread.sleep(500); boolean loginpage = getDriver().getPageSource().contains("Logon"); if (loginpage) { Actions builder = new Actions(getDriver()); builder.moveToElement(formLogonForm).build().perform(); LogUtil.log("Enter Username :" + user, LogLevel.MEDIUM); txtUserName.sendKeys(user); LogUtil.log("Enter Username :" + password, LogLevel.MEDIUM); txtPassword.sendKeys(password); btnSubmit.click(); WaitUtil.waitUntil(Timeout.FIVE_SEC); } return PageFactory.initElements(getDriver(), MainPage.class); }
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)); }//from ww w. ja v a 2 s .co m 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.actions.HoverAction.java
License:Apache License
@Override protected void execute(WebElement webElement, SeleniumBrowser browser, TestContext context) { super.execute(webElement, browser, context); Actions builder = new Actions(browser.getWebDriver()); builder.moveToElement(webElement).perform(); }
From source file:com.consol.citrus.selenium.client.WebClient.java
License:Apache License
/** * Select multiple items from a pull-down list. * * @param by/*from ww w.j a va 2 s. c om*/ * @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.constellio.sdk.tests.selenium.adapters.base.WebElementAdapter.java
License:Open Source License
public void rightClick() { WebElement webElement = getAdaptedSeleniumElement(); Actions oAction = new Actions(webDriver.getAdaptedDriver()); oAction.moveToElement(webElement); oAction.contextClick(webElement).build().perform(); }
From source file:com.dhenton9000.selenium.generic.GenericAutomationRepository.java
/** * Hover over the selected item/*from w ww .j a v a 2 s .co m*/ * * @param selectorChoice selection type, eg cssSelector * @param selectorValue the value to select by eg. '.myStyleClass' */ public void hoverOn(SELECTOR_CHOICE selectorChoice, String selectorValue) { Actions builder = new Actions(driver); By selectionBy = generateSelectorBy(selectorChoice, selectorValue); builder.moveToElement(driver.findElement(selectionBy)).build().perform(); }
From source file:com.dhenton9000.selenium.generic.GenericAutomationRepository.java
/** * Hover over the given WebElement/*from w w w . ja v a2s .c o m*/ * * @param e */ public void hoverOn(WebElement e) { Actions builder = new Actions(driver); builder.moveToElement(e).build().perform(); }
From source file:com.digi.selenium.util.BillNReload.Bill_n_Reload_Prepaid_Broadband_Util.java
/** * Read the 90Days Graph data//from w ww .j ava2s.co m */ protected void targetGraphData_90Days() { Wait<WebDriver> wait = new WebDriverWait(getDriver(), 30); JavascriptExecutor jse = (JavascriptExecutor) getDriver(); Map<String, String> mapbill = new HashMap<String, String>(); jse.executeScript("window.scrollBy(0,-500)", ""); jse.executeScript("window.scrollBy(0,225)", ""); wait.until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//*[name()='svg']/*[name()='g'][13]/*[name()='g'][1]"))); handleLink_ByText(AppConstants.DAYS_90); //Working :get the stroke attribute to get the color value of graph getDriver().manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); boolean breakIt = true; //Get the BillCycle Elements String billcyclerootNodeXpath = "//*[name()='svg']/*[name()='g'][13]/*[name()='g'][1]"; WebElement billcyclerootElement = getDriver().findElement(By.xpath(billcyclerootNodeXpath)); String billcyclechildXpath = "./*[name()='text']"; List<WebElement> listbillcyclechild = billcyclerootElement.findElements(By.xpath(billcyclechildXpath)); int eleListSize = listbillcyclechild.size(); // System.out.println("listChildElements.size() : " + listbillcyclechild.size()); //Get the BillCycle Graph , tooltip Elements String bcGraphRootNodeXpath = "//*[name()='svg']/*[name()='g'][6]/*[name()='g']"; WebElement bcGraphRootElement = getDriver().findElement(By.xpath(bcGraphRootNodeXpath)); String bcGraphChildXpath = "./*[name()='g']"; List<WebElement> listbcGraphChild = bcGraphRootElement.findElements(By.xpath(bcGraphChildXpath)); int bcGraphListSize = listbcGraphChild.size(); if (bcGraphListSize > 0) { targetBCGraphData_90Days = new HashMap(); } // System.out.println("bcGraphListSize.size() : " + listbcGraphChild.size()); for (int j = 0; j < eleListSize; j++) { int n = j + 1; Map<String, String> tempBCGData = new HashMap(); String billCycleDate = null; String bcAtrribute_color = null; while (true) { breakIt = true; try { //read the billcycle data from nodes String billchildNodePath_startDate = billcyclerootNodeXpath.concat("/*[name()='text']") .concat("[").concat(String.valueOf(n).concat("]").concat("/*[name()='tspan'][1]")); WebElement billelement_startDate = getDriver() .findElement(By.xpath(billchildNodePath_startDate)); //Thread.sleep(2000); String billAtrribute_startDate = billelement_startDate.getText(); String billchildNodePath_endDate = billcyclerootNodeXpath.concat("/*[name()='text']") .concat("[").concat(String.valueOf(n).concat("]").concat("/*[name()='tspan'][2]")); WebElement billelement_endDate = getDriver().findElement(By.xpath(billchildNodePath_endDate)); String billAtrribute_endDate = billelement_endDate.getText(); billCycleDate = billAtrribute_startDate.concat("_").concat(billAtrribute_endDate); //System.out.println("Bill Cycle : '" + n+"' -->"+ billCycleDate); //read the billcycle graph data - color, tooltip from nodes String billchildNodePath_color = bcGraphRootNodeXpath.concat("/*[name()='g']").concat("[") .concat(String.valueOf(n).concat("]").concat("/*[name()='path']")); //System.out.println("Node billchildNodePath_color : " + billchildNodePath_color); WebElement billelement_color = getDriver().findElement(By.xpath(billchildNodePath_color)); bcAtrribute_color = billelement_color.getAttribute("stroke"); String colorMap = AppConstants.COLOR.concat(AppConstants.BEGIN_BRACKET).concat(billCycleDate) .concat(AppConstants.CLOSE_BRACKET); tempBCGData.put(colorMap, bcAtrribute_color); Actions builder = new Actions(getDriver()); String childMouseHouverNode = bcGraphRootNodeXpath.concat("/*[name()='g']").concat("[") .concat(String.valueOf(n).concat("]")); builder.moveToElement(getDriver().findElement(By.xpath(childMouseHouverNode))).perform(); WebElement mouseHoverNodeElement = getDriver() .findElement(By.xpath("//div[9]/div[1]/div[1]/div[2]/div/div/div")); if (mouseHoverNodeElement != null) { String toolTipText = mouseHoverNodeElement.getText(); //System.out.println("toolTipText : '" + n+"' "+toolTipText ); String toolTipTextMap = AppConstants.TOOL_TIP_TEXT.concat(AppConstants.BEGIN_BRACKET) .concat(billCycleDate).concat(AppConstants.CLOSE_BRACKET); //tempBCGData.put(toolTipTextMap, toolTipText.replaceAll("\n", "")); tempBCGData.put(toolTipTextMap, toolTipText); builder.moveToElement(getDriver().findElement(By.xpath(billchildNodePath_startDate))) .click().perform(); } } catch (Exception e) { if (e.getMessage().contains("element is not attached")) { //System.out.println("Error: Element 4 "); breakIt = false; } } if (breakIt) { break; } } //while loop ends targetBCGraphData_90Days.put(billCycleDate, tempBCGData); } //for loop ends }
From source file:com.digi.selenium.util.BillNReload.Bill_n_Reload_Prepaid_Broadband_Util.java
protected void targetGraphData_60Days() { JavascriptExecutor jse = (JavascriptExecutor) getDriver(); Wait<WebDriver> wait = new WebDriverWait(getDriver(), 30); jse.executeScript("window.scrollBy(0,-500)", ""); jse.executeScript("window.scrollBy(0,225)", ""); handleLink_ByText(AppConstants.DAYS_60); Map<String, String> mapbill = new HashMap<String, String>(); wait.until(ExpectedConditions/*from ww w . j a va 2s. c o m*/ .visibilityOfElementLocated(By.xpath("//*[name()='svg']/*[name()='g'][13]/*[name()='g'][1]"))); //Working :get the stroke attribute to get the color value of graph getDriver().manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); boolean breakIt = true; //Get the BillCycle Elements String billcyclerootNodeXpath = "//*[name()='svg']/*[name()='g'][13]/*[name()='g'][1]"; WebElement billcyclerootElement = getDriver().findElement(By.xpath(billcyclerootNodeXpath)); String billcyclechildXpath = "./*[name()='text']"; List<WebElement> listbillcyclechild = billcyclerootElement.findElements(By.xpath(billcyclechildXpath)); int eleListSize = listbillcyclechild.size(); // System.out.println("listChildElements.size() : " + listbillcyclechild.size()); //Get the BillCycle Graph , tooltip Elements String bcGraphRootNodeXpath = "//*[name()='svg']/*[name()='g'][6]/*[name()='g']"; WebElement bcGraphRootElement = getDriver().findElement(By.xpath(bcGraphRootNodeXpath)); String bcGraphChildXpath = "./*[name()='g']"; List<WebElement> listbcGraphChild = bcGraphRootElement.findElements(By.xpath(bcGraphChildXpath)); int bcGraphListSize = listbcGraphChild.size(); if (bcGraphListSize > 0) { targetBCGraphData_60Days = new HashMap(); } // System.out.println("bcGraphListSize.size() : " + listbcGraphChild.size()); for (int j = 0; j < eleListSize; j++) { int n = j + 1; Map<String, String> tempBCGData = new HashMap(); String billCycleDate = null; String bcAtrribute_color = null; while (true) { breakIt = true; try { //read the billcycle data from nodes String billchildNodePath_startDate = billcyclerootNodeXpath.concat("/*[name()='text']") .concat("[").concat(String.valueOf(n).concat("]").concat("/*[name()='tspan'][1]")); WebElement billelement_startDate = getDriver() .findElement(By.xpath(billchildNodePath_startDate)); //Thread.sleep(2000); String billAtrribute_startDate = billelement_startDate.getText(); String billchildNodePath_endDate = billcyclerootNodeXpath.concat("/*[name()='text']") .concat("[").concat(String.valueOf(n).concat("]").concat("/*[name()='tspan'][2]")); WebElement billelement_endDate = getDriver().findElement(By.xpath(billchildNodePath_endDate)); String billAtrribute_endDate = billelement_endDate.getText(); billCycleDate = billAtrribute_startDate.concat("_").concat(billAtrribute_endDate); //System.out.println("Bill Cycle : '" + n+"' -->"+ billCycleDate); //read the billcycle graph data - color, tooltip from nodes String billchildNodePath_color = bcGraphRootNodeXpath.concat("/*[name()='g']").concat("[") .concat(String.valueOf(n).concat("]").concat("/*[name()='path']")); //System.out.println("Node billchildNodePath_color : " + billchildNodePath_color); WebElement billelement_color = getDriver().findElement(By.xpath(billchildNodePath_color)); bcAtrribute_color = billelement_color.getAttribute("stroke"); String colorMap = AppConstants.COLOR.concat(AppConstants.BEGIN_BRACKET).concat(billCycleDate) .concat(AppConstants.CLOSE_BRACKET); tempBCGData.put(colorMap, bcAtrribute_color); Actions builder = new Actions(getDriver()); String childMouseHouverNode = bcGraphRootNodeXpath.concat("/*[name()='g']").concat("[") .concat(String.valueOf(n).concat("]")); builder.moveToElement(getDriver().findElement(By.xpath(childMouseHouverNode))).perform(); WebElement mouseHoverNodeElement = getDriver() .findElement(By.xpath("//div[9]/div[1]/div[1]/div[2]/div/div/div")); if (mouseHoverNodeElement != null) { String toolTipText = mouseHoverNodeElement.getText(); //System.out.println("toolTipText : '" + n+"' "+toolTipText ); String toolTipTextMap = AppConstants.TOOL_TIP_TEXT.concat(AppConstants.BEGIN_BRACKET) .concat(billCycleDate).concat(AppConstants.CLOSE_BRACKET); tempBCGData.put(toolTipTextMap, toolTipText); builder.moveToElement(getDriver().findElement(By.xpath(billchildNodePath_startDate))) .click().perform(); } } catch (Exception e) { if (e.getMessage().contains("element is not attached")) { //System.out.println("Error: Element 4 "); breakIt = false; } } if (breakIt) { break; } } //while loop ends targetBCGraphData_60Days.put(billCycleDate, tempBCGData); } //for loop ends }