use of org.openqa.selenium.JavascriptExecutor in project ghostdriver by detro.
the class SessionBasicTest method closeShouldNotTerminatePhantomJSProcess.
@Test(expected = NoSuchWindowException.class)
public void closeShouldNotTerminatePhantomJSProcess() throws MalformedURLException {
// By default, 1 window is created when Driver is launched
WebDriver d = getDriver();
assertEquals(1, d.getWindowHandles().size());
// Check the number of windows
d.navigate().to("about:blank");
assertEquals(1, d.getWindowHandles().size());
// Create a new window
((JavascriptExecutor) d).executeScript("window.open('http://www.google.com','google');");
assertEquals(2, d.getWindowHandles().size());
// Close 1 window and check that 1 is left
d.close();
assertEquals(1, d.getWindowHandles().size());
// Switch to that window
d.switchTo().window("google");
assertNotNull(d.getWindowHandle());
// Close the remaining window and check now there are no windows available
d.close();
assertEquals(0, d.getWindowHandles().size());
// This should throw a "NoSuchWindowException": the Driver is still running, but no Session/Window are left
d.getWindowHandle();
}
use of org.openqa.selenium.JavascriptExecutor in project ghostdriver by detro.
the class ElementJQueryEventsTest method shouldBeAbleToClickAndEventsBubbleUpUsingJquery.
@Test
public void shouldBeAbleToClickAndEventsBubbleUpUsingJquery() {
final String buttonId = "clickme";
server.setHttpHandler("GET", new HttpRequestCallback() {
@Override
public void call(HttpServletRequest req, HttpServletResponse res) throws IOException {
res.getOutputStream().println("<html>\n" + "<head>\n" + "<script src=\"//ajax.googleapis.com/ajax/libs/jquery/" + mJqueryVersion + "/jquery.min.js\"></script>\n" + "<script type=\"text/javascript\">\n" + " var clicked = false;" + " $(document).ready(function() {" + " $('#" + buttonId + "').bind('click', function(e) {" + " clicked = true;" + " });" + " });\n" + "</script>\n" + "</head>\n" + "<body>\n" + " <a href='#' id='" + buttonId + "'>click me</a>\n" + "</body>\n" + "</html>");
}
});
WebDriver d = getDriver();
d.get(server.getBaseUrl());
// Click on the link inside the page
d.findElement(By.id(buttonId)).click();
// Check element was clicked as expected
assertTrue((Boolean) ((JavascriptExecutor) d).executeScript("return clicked;"));
}
use of org.openqa.selenium.JavascriptExecutor in project java.webdriver by sayems.
the class HoverWithJavascript method accept.
/**
* Uses {@code JavascriptExecutor} with the specified driver to perform a hover on the specified element.
*
* @param driver the {@code WebDriver} to use with {@code JavascriptExecutor} for performing the hover
* @param element the {@code WebElement} to hover
*/
public void accept(WebDriver driver, WebElement element) {
String script = "if(document.createEvent) {" + "var evObj = document.createEvent('MouseEvents');" + "evObj.initEvent( 'mouseover', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);" + "arguments[0].dispatchEvent(evObj);" + "} else if( document.createEventObject ) {" + "arguments[0].fireEvent('onmouseover');" + "}";
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript(script, element);
}
use of org.openqa.selenium.JavascriptExecutor in project java.webdriver by sayems.
the class GetWindowName method main.
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.navigate().to("http://www.google.com");
JavascriptExecutor js = (JavascriptExecutor) driver;
System.out.println(js.executeScript("return window.name"));
}
use of org.openqa.selenium.JavascriptExecutor in project saga by timurstrekalov.
the class GenericInstrumentingBrowser method get.
@Override
public void get(final String url) {
driver.get(url);
final JavascriptExecutor js = (JavascriptExecutor) driver;
WebDriverUtils.waitForWindowJavaScriptVariableToBePresent(js, SAGA_NAMESPACE);
new SafeJavascriptWait(js).withTimeout(config.getBackgroundJavaScriptTimeout(), TimeUnit.MILLISECONDS).until(new Predicate<JavascriptExecutor>() {
@Override
public boolean apply(final JavascriptExecutor input) {
logger.debug("Waiting for test runner to finish");
return Boolean.TRUE.equals(input.executeScript("return " + SAGA_NAMESPACE + ".completed()"));
}
});
}
Aggregations