List of usage examples for org.openqa.selenium JavascriptExecutor executeScript
Object executeScript(String script, Object... args);
From source file:com.coderoad.automation.rocketTruedx.RocketTruedxNaBasePage.java
License:Open Source License
/** * this method send the click () event to the web element. * //from w w w.ja v a 2s.c o m * @param elem the elem */ protected void click(WebElement elem) { // elem.click(); JavascriptExecutor executor = (JavascriptExecutor) getDriver(); executor.executeScript("arguments[0].click();", elem); }
From source file:com.cognifide.qa.bb.aem.dialog.classic.field.image.AemImageSetterHelper.java
License:Apache License
private void executeJavascript(String imagePlaceholderId) { frameSwitcher.switchTo("/"); JavascriptExecutor js = (JavascriptExecutor) webDriver; LOG.debug("executing javascript with argument: '{}'", imagePlaceholderId); bobcatWait.withTimeout(Timeouts.MEDIUM).until(driver -> { boolean executedSuccessfully = false; do {/*from ww w .j a va 2 s . co m*/ try { String javaScript = getJavascriptToExecute(); js.executeScript(javaScript, imagePlaceholderId); executedSuccessfully = true; } catch (WebDriverException wde) { LOG.warn("error while executing JavaScript: '{}'", wde.getMessage(), wde); } catch (IOException ioe) { String msg = "error while loading JavaScript from file: " + IMAGE_SETTER_JS_FILENAME; LOG.error(msg, ioe); throw new BobcatRuntimeException(msg); } } while (!executedSuccessfully); return executedSuccessfully; }, DELAY_BEFORE_RETRY_IN_SECONDS); frameSwitcher.switchBack(); }
From source file:com.consol.citrus.selenium.actions.JavaScriptAction.java
License:Apache License
@Override protected void execute(SeleniumBrowser browser, TestContext context) { try {/*from www .j av a2 s . co m*/ if (browser.getWebDriver() instanceof JavascriptExecutor) { JavascriptExecutor jsEngine = ((JavascriptExecutor) browser.getWebDriver()); jsEngine.executeScript(context.replaceDynamicContentInString(script), context.resolveDynamicValuesInArray(arguments.toArray())); List<String> errors = new ArrayList<>(); List<Object> errorObjects = (List<Object>) jsEngine .executeScript("return window._selenide_jsErrors", new Object[] {}); if (errorObjects != null) { for (Object error : errorObjects) { errors.add(error.toString()); } } context.setVariable(SeleniumHeaders.SELENIUM_JS_ERRORS, errors); for (String expected : expectedErrors) { if (!errors.contains(expected)) { throw new ValidationException("Missing JavaScript error " + expected); } } } else { log.warn("Skip javascript action because web driver is missing javascript features"); } } catch (WebDriverException e) { throw new CitrusRuntimeException("Failed to execute JavaScript code", e); } }
From source file:com.constellio.sdk.tests.selenium.adapters.base.WebDriverAdapter.java
License:Open Source License
@Override public Object executeScript(String script, Object... args) { JavascriptExecutor executor = (JavascriptExecutor) adapted; return executor.executeScript(script, convertScriptArguments(args)); }
From source file:com.contactenergy.Tests.ContactBrowserTest.java
public void scrollto(String elementxpath) { JavascriptExecutor je = (JavascriptExecutor) driver.get(); WebElement element = driver.get().findElement(By.xpath(elementxpath)); je.executeScript("arguments[0].scrollIntoView(true);", element); }
From source file:com.digi.selenium.util.BillNReload.Bill_n_Reload_Prepaid_Broadband_Util.java
protected void targetTotalReload() { try {//from www. j a va 2 s . c o m JavascriptExecutor jse = (JavascriptExecutor) getDriver(); jse.executeScript("window.scrollBy(0,300)", ""); waitgetForPageLoad(30).until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//*[@id='content']/div[9]/div[2]/div/div[1]/div[2]/p"))); //String expectedTotalReload = "RM 0.00"; //*[@id="content"]/div[9]/div[2]/div/div[1]/div[2]/p actualTotalReload = getWebElement_By_xpath("//*[@id='content']/div[9]/div[2]/div/div[1]/div[2]/p") .getText(); System.out.println("actualTotalReload : " + actualTotalReload); jse.executeScript("window.scrollBy(0,-300)", ""); } catch (Exception e) { log.error("Fail : To validate the target Total Reload"); } }
From source file:com.digi.selenium.util.BillNReload.Bill_n_Reload_Prepaid_Broadband_Util.java
protected void target_reloadbtn() { JavascriptExecutor jse = (JavascriptExecutor) getDriver(); jse.executeScript("window.scrollBy(0,-500)", ""); boolean breakIt; jse.executeScript("window.scrollBy(0,400)", ""); while (true) { breakIt = true;/* w w w. ja va 2 s. com*/ try { //*[@id="planDetails"]/div[2]/div[1]/div[4]/a WebElement reload = getDriver().findElement(By.linkText("Reload balance")); reload.click(); log.info("Success: Reload button is clicked"); waitForPageLoad(100); } catch (Exception e) { log.error("Fail : Failed to click on reload button"); breakIt = false; //System.out.println(e); //e.printStackTrace(); //e.printStackTrace(); //System.exit(0); } if (breakIt) { break; } } }
From source file:com.digi.selenium.util.BillNReload.Bill_n_Reload_Prepaid_Broadband_Util.java
protected void clickOnRadioRM50() { boolean breakIt; while (true) { breakIt = true;//from w w w .j a va 2s .c o m try { // Put email id on text field as it can not be blank //*[@id="reloadForm__email"] WebElement emailtxt = getDriver().findElement(By.id("reloadForm__email")); System.out.println(emailtxt.isEnabled()); if (emailtxt.isEnabled()) { handleInputField_ByID("reloadForm__email", AppConstants.EMAIL); Thread.sleep(500); } JavascriptExecutor js1 = (JavascriptExecutor) getDriver(); //js1.executeScript("window.scrollBy(0,400)", ""); //*[@id="prepaidReloadForm"]/ul/li[2]/label/div WebElement radio = getDriver() .findElement(By.xpath("//*[@id='prepaidReloadForm']/ul/li[4]/label/div")); radio.click(); // now select check box to accept license agreement WebElement checkbox = getDriver().findElement(By.xpath("//*[@id='prepaidReloadForm']/label/div")); checkbox.click(); // click on proceed button after selecting radio button and check box // WebElement elementproceed=getDriver().findElement(By.xpath("//*[@id='proceedBtn']")); //*[@id="proceedBtn"] WebElement proceed = (new WebDriverWait(getDriver(), 1000)) .until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='proceedBtn']"))); proceed.click(); waitForPageLoad(100); Thread.sleep(500); JavascriptExecutor js = (JavascriptExecutor) getDriver(); js.executeScript("window.scrollBy(0,500)", ""); } catch (Exception e) { System.out.println(e); breakIt = false; e.printStackTrace(); log.error("Fail : Failed to Reload amount."); System.exit(0); } if (breakIt) { break; } } //while ends }
From source file:com.digi.selenium.util.BillNReload.Bill_n_Reload_Prepaid_Broadband_Util.java
protected void targetYAxisData(int index) { JavascriptExecutor jse = (JavascriptExecutor) getDriver(); jse.executeScript("window.scrollBy(0,-800)", ""); getWebElement_By_xpath("//*[@id='content']/div[9]/div[1]/div[2]/ul/li[" + index + "]/a").click(); Wait<WebDriver> wait = new WebDriverWait(getDriver(), 30); if (index == 1) jse.executeScript("window.scrollBy(0,210)", ""); wait.until(ExpectedConditions//from w w w.j a va2 s . c om .visibilityOfElementLocated(By.xpath("//*[name()='svg']/*[name()='g'][13]/*[name()='g'][2]"))); //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 yaxisrootNodeXpath = "//*[name()='svg']/*[name()='g'][13]/*[name()='g'][2]"; WebElement yaxisrootElement = getDriver().findElement(By.xpath(yaxisrootNodeXpath)); String yaxischildXpath = "./*[name()='text']"; listyaxischild = yaxisrootElement.findElements(By.xpath(yaxischildXpath)); int eleListSize = listyaxischild.size(); // String targetrootdatapath= "//*[@id='content']/div[9]/div[1]/div[1]/div[2]/div/div/svg/g[13]/g[2]"; if (index == 1) System.out.println("===========30 Days Y-AxisData========"); else { if (index == 2) System.out.println("===========60 Days Y-AxisData========"); else System.out.println("===========90 Days Y-AxisData========"); } }
From source file:com.digi.selenium.util.BillNReload.Bill_n_Reload_Prepaid_Broadband_Util.java
protected void targetTableData() { Wait<WebDriver> waittable = new WebDriverWait(getDriver(), 30); JavascriptExecutor jse = (JavascriptExecutor) getDriver(); //if(index>0) jse.executeScript("window.scrollBy(0,-800)", ""); getWebElement_By_xpath("//*[@id='content']/div[9]/div[1]/div[2]/ul/li[1]").click(); jse.executeScript("window.scrollBy(0,800)", ""); waittable.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='details-table']"))); WebElement headertable = getDriver().findElement(By.xpath("//*[@id='details-table']")); List<WebElement> header = headertable.findElements(By.xpath("//*[@id='billhistory']/tr")); System.out.println("===========Table Data========"); // And iterate over them, getting the header data for (WebElement node : header) { List<WebElement> cells = node.findElements(By.tagName("th")); for (WebElement cell : cells) headerlist.add(cell.getText()); }// ww w. j a v a 2s .c o m // Now get all the TR elements from the table WebElement table = getDriver().findElement(By.xpath("//*[@id='details-table']/tbody")); List<WebElement> rows = table.findElements(By.tagName("tr")); // And iterate over them, getting the cells for (WebElement row : rows) { List<WebElement> rowcells = row.findElements(By.tagName("td")); for (WebElement cell : rowcells) tabledatalist.add(cell.getText()); } }