Refine search
@Test public void testAccountChooserPopulatesUsernameNotEmailWhenOriginIsUAAorLDAP() throws Exception { String userUAA = "{\"userId\":\"1\",\"username\":\"userUAA\",\"origin\":\"uaa\",\"email\":\"user@uaa.org\"}"; String userLDAP = "{\"userId\":\"2\",\"username\":\"userLDAP\",\"origin\":\"ldap\",\"email\":\"user@ldap.org\"}"; String userExternal = "{\"userId\":\"3\",\"username\":\"userExternal\",\"origin\":\"external\",\"email\":\"user@external.org\"}"; String zoneUrl = createDiscoveryZone(); webDriver.get(zoneUrl); webDriver.manage().deleteAllCookies(); JavascriptExecutor js = (JavascriptExecutor) webDriver; js.executeScript("document.cookie = \"Saved-Account-1=" + URLEncoder.encode(userUAA, StandardCharsets.UTF_8.name()) + ";path=/;domain=testzone3.localhost\""); js.executeScript("document.cookie = \"Saved-Account-2=" + URLEncoder.encode(userLDAP, StandardCharsets.UTF_8.name()) + ";path=/;domain=testzone3.localhost\""); js.executeScript("document.cookie = \"Saved-Account-3=" + URLEncoder.encode(userExternal, StandardCharsets.UTF_8.name()) + ";path=/;domain=testzone3.localhost\""); webDriver.navigate().refresh(); assertEquals(3, webDriver.findElements(By.cssSelector("span.email-address")).size()); webDriver.findElement(By.xpath("//span[contains(text(), 'userUAA')]")).click(); assertEquals("userUAA", webDriver.findElement(By.id("username")).getAttribute("value")); webDriver.navigate().back(); webDriver.findElement(By.xpath("//span[contains(text(), 'userLDAP')]")).click(); assertEquals("userLDAP", webDriver.findElement(By.id("username")).getAttribute("value")); webDriver.navigate().back(); webDriver.findElement(By.xpath("//span[contains(text(), 'userExternal')]")).click(); assertEquals("user@external.org", webDriver.findElement(By.id("username")).getAttribute("value")); webDriver.manage().deleteAllCookies(); }
@Test public void testLoginReloadRetainsFormRedirect() { String redirectUri = "http://expected.com"; webDriver.get(baseUrl + "/oauth/authorize?client_id=test&redirect_uri="+redirectUri); ((JavascriptExecutor)webDriver).executeScript("document.getElementsByName('X-Uaa-Csrf')[0].value=''"); webDriver.manage().deleteCookieNamed("JSESSIONID"); webDriver.findElement(By.xpath("//input[@value='Sign in']")).click(); assertThat(webDriver.getCurrentUrl(), Matchers.containsString("/login")); assertThat(webDriver.findElement(By.name("form_redirect_uri")).getAttribute("value"), Matchers.containsString("redirect_uri="+redirectUri)); }
@Test public void testStelenessAndJavascriptOnWebElement() { WebElement inStale = browser.findElement(By.className("stale")).findElement(By.className("in-stale")); makeStale.click(); JavascriptExecutor executor = (JavascriptExecutor) browser; installator.install(); executor.executeScript("Graphene.jQuery(arguments[0]).trigger('blur')", inStale); }
// Assume driver is a valid WebDriver instance that // has been properly instantiated elsewhere. WebElement element = driver.findElement(By.id("gbqfd")); JavascriptExecutor executor = (JavascriptExecutor)driver; executor.executeScript("arguments[0].click();", element);
WebElement inp = driver.findElement(By.className("tt-hint")); //Option 1 remove the disabled attribute JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("arguments[0].removeAttribute('disabled')",inp); inp.sendKeys("val"); //Option 2 go for javascript set value js.executeScript("arguments[0].value=arguments[1]",inp,"val");
@Test public void testStelenessAndJavascriptOnWebDriver() { WebElement stale = browser.findElement(By.className("stale")); makeStale.click(); JavascriptExecutor executor = (JavascriptExecutor) browser; installator.install(); executor.executeScript("Graphene.jQuery(arguments[0]).trigger('blur')", stale); }
WebDriver driver = new FirefoxDriver(); JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript("document.getElementsByName('body')[0].setAttribute('type', 'text');"); driver.findElement(By.xpath("//input[@name='body']")).clear(); driver.findElement(By.xpath("//input[@name='body']")).sendKeys("Ripon: body text");
DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox(); desiredCapabilities.setCapability(CapabilityType.HAS_NATIVE_EVENTS,true); WebDriver driver = new FirefoxDriver(desiredCapabilities); driver.get("http://yizeng.me/2014/01/31/test-wysiwyg-editors-using-selenium-webdriver/"); WebElement frame = driver.findElement(By.id("tinymce-editor_ifr")); driver.switchTo().frame(frame); WebElement body = driver.findElement(By.id("tinymce")); JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript("arguments[0].innerHTML = '<h1>Heading</h1>Hello There'",body);
public void verifyProfilePhoto(String courseId, String studentName, String urlRegex) { String rowId = getStudentRowId(courseId, studentName); verifyImageUrl(urlRegex, browser.driver .findElement(By.id("studentphoto-c" + rowId)) .findElement(By.tagName("img")) .getAttribute("src")); WebElement photo = browser.driver.findElement(By.id("studentphoto-c" + rowId)) .findElement(By.cssSelector(".profile-pic-icon-click > img")); JavascriptExecutor jsExecutor = (JavascriptExecutor) browser.driver; jsExecutor.executeScript("arguments[0].scrollIntoView(true); window.scrollBy(0, -100);", photo); Actions action = new Actions(browser.driver); action.click(photo).build().perform(); verifyImageUrl(urlRegex, browser.driver .findElement(By.id("studentphoto-c" + rowId)) .findElement(By.cssSelector(".popover-content > .profile-pic")) .getAttribute("src")); }
// assuming JS is enabled for this instance of driver JavascriptExecutor js = (JavascriptExecutor)driver; int viewportWidth = (Integer)js.executeScript("return window.innerWidth;"); int viewportHeight = (Integer)js.executeScript("return window.innerHeight;"); List<WebElement> list = driver.findElements(By.cssSelector("whatever")); for (Iterator<WebElement> iter = list.iterator(); iter.hasNext(); ) { WebElement elem = iter.next(); Point p = elem.getLocation(); if ((p.getX() > viewportWidth) || (p.getY() > viewportHeight)) { iter.remove(); } }
driver.switchTo().frame("iframe-id"); WebElement body = driver.findElement(By.xpath("//body")); body.click(); JavascriptExecutor executor = (JavascriptExecutor)driver; executor.executeScript("arguments[0].innerHTML = 'Hello World!'", body);
WebDriver driver = new ChromeDriver(); driver.get("http://demo.vaadin.com/sampler/#ui/grids-and-trees/table"); List<WebElement> elements = driver.findElements(By.xpath("//tr[starts-with(@class,'v-table-row')]")); JavascriptExecutor js = (JavascriptExecutor) driver; for (WebElement element : elements) { if (element.isDisplayed()) { js.executeScript("arguments[0].className=arguments[0].className+' v-selected';", element); } }
List<WebElement> checkboxes = driver.findElements(By.cssSelector("input[type=checkbox]")); JavascriptExecutor js = (JavascriptExecutor) driver; if (checkboxes.isEmpty()) { System.out.println("No Checkbox present in the page"); } else { for (WebElement checkbox : checkboxes) { if (checkbox.isDisplayed()) { String text=(String) js.executeScript("return arguments[0].nextSibling.textContent.trim();", checkbox); System.out.println(text); } } }
protected void blur() { if (SeleniumTestsContextManager.isWebTest() && "input".equalsIgnoreCase(element.getTagName())) { try { ((JavascriptExecutor) driver).executeScript("arguments[0].blur();", element); } catch (Exception e) { logger.error(e); } } }
public void acceptAlertDialog(Consumer<SebContext> showDialog) { boolean supportsAlerts = isAlertSupported(); if (!supportsAlerts) { ((JavascriptExecutor) context.getDriver()).executeScript("window.alert = function(msg){};"); } showDialog.accept(context); if (supportsAlerts) { context.getDriver().switchTo().alert().accept(); } }
Point iframeLocation = iframe.getLocation(); BufferedImage img; try { return null; int iframeHeight = iframe.getSize().getHeight(); SelenideTargetLocator switchTo = new SelenideTargetLocator(driver.config(), driver.getWebDriver()); switchTo.frame(iframe); int iframeWidth = ((Long) ((JavascriptExecutor) webdriver).executeScript("return document.body.clientWidth")).intValue(); if (iframeHeight > img.getHeight()) { iframeHeight = img.getHeight() - iframeLocation.getY(); iframeWidth = img.getWidth() - iframeLocation.getX(); Point elementLocation = element.getLocation(); int elementWidth = element.getSize().getWidth(); int elementHeight = element.getSize().getHeight();
@Override public Boolean apply(WebDriver webDriver) { if (!driver.findElement(By.cssSelector(LOGIN_DROPDOWN_TRIGGER_CSS)) .getAttribute("class") .contains("active")) { ((JavascriptExecutor) driver).executeScript( "$j('.ajaxLogin .avatar-container').trigger('click')"); return false; } return true; } });
WebDriver driver = new ChromeDriver(); driver.get("http://bubble-export.com/lpg2/"); JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("window.onbeforeunload = function() {};"); driver.get("http://google.com");
public void focus() { invoker.doJAction("Scroll Element into the center of View and Focus on it", () -> { ((JavascriptExecutor) getDriver()) .executeScript("arguments[0].scrollIntoView({block: 'center'});", getWebElement()); Dimension size = getWebElement().getSize(); //for scroll to object new Actions(getDriver()).moveToElement(getWebElement(), size.width / 2, size.height / 2) .build().perform(); }); }
public static void clearBrowserSession(WebDriver driver) { if (StepEventBus.getEventBus().isDryRun()) { return; } if (((WebDriverFacade) driver).isInstantiated()) { driver.manage().deleteAllCookies(); try { ((JavascriptExecutor) driver).executeScript(String.format("window.localStorage.clear();")); } catch (WebDriverException driverDoesntSupportJavascriptTooBad) {} } } }