Search in sources :

Example 1 with JavascriptExecutor

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();
}
Also used : WebDriver(org.openqa.selenium.WebDriver) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Test(org.junit.Test)

Example 2 with JavascriptExecutor

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;"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebDriver(org.openqa.selenium.WebDriver) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) HttpRequestCallback(ghostdriver.server.HttpRequestCallback) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with JavascriptExecutor

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);
}
Also used : JavascriptExecutor(org.openqa.selenium.JavascriptExecutor)

Example 4 with JavascriptExecutor

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"));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 5 with JavascriptExecutor

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()"));
        }
    });
}
Also used : JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) SafeJavascriptWait(com.github.timurstrekalov.saga.core.webdriver.SafeJavascriptWait)

Aggregations

JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)40 WebElement (org.openqa.selenium.WebElement)20 PublicAtsApi (com.axway.ats.common.PublicAtsApi)9 WebDriver (org.openqa.selenium.WebDriver)7 RealHtmlElementState (com.axway.ats.uiengine.utilities.realbrowser.html.RealHtmlElementState)4 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)4 HiddenHtmlElementState (com.axway.ats.uiengine.utilities.hiddenbrowser.HiddenHtmlElementState)3 Test (org.junit.Test)3 Dimension (org.openqa.selenium.Dimension)3 RemoteWebElement (org.openqa.selenium.remote.RemoteWebElement)3 Select (org.openqa.selenium.support.ui.Select)3 VerificationException (com.axway.ats.uiengine.exceptions.VerificationException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)2 MobileDriver (com.axway.ats.uiengine.MobileDriver)1 MobileOperationException (com.axway.ats.uiengine.exceptions.MobileOperationException)1 SeleniumOperationException (com.axway.ats.uiengine.exceptions.SeleniumOperationException)1 MobileElementState (com.axway.ats.uiengine.utilities.mobile.MobileElementState)1 SafeJavascriptWait (com.github.timurstrekalov.saga.core.webdriver.SafeJavascriptWait)1