Java Code Examples for org.openqa.selenium.interactions.Actions#moveToElement()
The following examples show how to use
org.openqa.selenium.interactions.Actions#moveToElement() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SeleniumSpec.java From bdt with Apache License 2.0 | 6 votes |
/** * Type a {@code text} on an numbered {@code index} previously found element. * * @param nullablestring * @param index */ @When("I type {string} on the element on index '{int}'") public void seleniumType(String nullablestring, Integer index) { String text = NullableString.transform(nullablestring); assertThat(this.commonspec, scenario, commonspec.getPreviousWebElements()).as("There are less found elements than required") .hasAtLeast(index); while (text.length() > 0) { Actions actions = new Actions(commonspec.getDriver()); if (-1 == text.indexOf("\\n")) { actions.moveToElement(commonspec.getPreviousWebElements().getPreviousWebElements().get(index)); actions.click(); actions.sendKeys(text); actions.build().perform(); text = ""; } else { actions.moveToElement(commonspec.getPreviousWebElements().getPreviousWebElements().get(index)); actions.click(); actions.sendKeys(text.substring(0, text.indexOf("\\n"))); actions.build().perform(); text = text.substring(text.indexOf("\\n") + 2); } } }
Example 2
Source File: SeleniumSpec.java From bdt with Apache License 2.0 | 6 votes |
/** * Delete or replace the text on a numbered {@code index} previously found element. * * @param index */ @When("^I delete the text '(.+?)' on the element on index '(\\d+)'( and replace it for '(.+?)')?$") public void seleniumDelete(String text, Integer index, String replacement) { assertThat(this.commonspec, scenario, commonspec.getPreviousWebElements()).as("There are less found elements than required") .hasAtLeast(index); Actions actions = new Actions(commonspec.getDriver()); actions.moveToElement(commonspec.getPreviousWebElements().getPreviousWebElements().get(index), (text.length() / 2), 0); for (int i = 0; i < (text.length() / 2); i++) { actions.sendKeys(Keys.ARROW_LEFT); actions.build().perform(); } for (int i = 0; i < text.length(); i++) { actions.sendKeys(Keys.DELETE); actions.build().perform(); } if (replacement != null && replacement.length() != 0) { actions.sendKeys(replacement); actions.build().perform(); } }
Example 3
Source File: AllPostsPage.java From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License | 6 votes |
private void goToParticularPostPage(String title) { List<WebElement> allPosts = postsContainer.findElements(By.className("title")); for (WebElement ele : allPosts) { if (ele.getText().equals(title)) { Actions builder = new Actions(driver); builder.moveToElement(ele); builder.click(driver.findElement( By.cssSelector(".edit>a"))); // Generate the composite action. Action compositeAction = builder.build(); // Perform the composite action. compositeAction.perform(); break; } } }
Example 4
Source File: StatisticDataIT.java From AisAbnormal with GNU Lesser General Public License v3.0 | 6 votes |
private void clickOnACell() throws InterruptedException { zoomIntoHelsinore(); waitForCellsToBeDisplayed(); WebElement map = getMap(); Actions actions = new Actions(browser); actions.moveToElement(map, map.getSize().getWidth() / 2, map.getSize().getHeight() / 2); actions.click(); actions.perform(); // Cursor position is exactly in the center of the map browser.findElement(By.id("tab-map")).click(); assertEquals("(56°02'05.7\"N, 12°38'59.7\"E)", browser.findElement(By.cssSelector("div#cursorpos.useroutput p")).getText()); // Assert statistic data for correct cell displayed final String expectedCellInfo = "Cell id 6249302540 (56°02'06.5\"N,12°38'53.8\"E) - (56°02'00\"N,12°39'00.3\"E)"; By actualCellInfoElement = By.cssSelector("div.cell-data-contents > h5"); wait.until(ExpectedConditions.textToBePresentInElement(actualCellInfoElement, expectedCellInfo)); }
Example 5
Source File: NavigationService.java From senbot with MIT License | 5 votes |
/** * Hovers the mouse over the given element * @param locator The element locator */ public void mouseHoverOverElement(By locator) { SynchronisationService synchronisationService = new SynchronisationService(); synchronisationService.waitAndAssertForExpectedCondition(ExpectedConditions.visibilityOfElementLocated(locator)); WebElement element = getWebDriver().findElement(locator); Actions builder = new Actions(getWebDriver()); Actions hoverOverRegistrar = builder.moveToElement(element); hoverOverRegistrar.perform(); }
Example 6
Source File: HTMLSelectElementTest.java From htmlunit with Apache License 2.0 | 5 votes |
/** * @throws Exception if an error occurs */ @Test @Alerts("mouse over") @BuggyWebDriver(FF = "mouse overmouse overmouse over", FF60 = "mouse overmouse overmouse overmouse over", FF68 = "mouse overmouse overmouse over") public void mouseOver() throws Exception { final String html = "<html>\n" + " <head>\n" + " <script>\n" + " function doTest() {\n" + " document.title += 'mouse over';\n" + " }\n" + " </script>\n" + " </head>\n" + "<body>\n" + " <form id='form1'>\n" + " <select name='select1' id='select1' size='4' onmouseover='doTest()'>\n" + " <option value='option1' id='option1' >Option1</option>\n" + " <option value='option2' id='option2'>Option2</option>\n" + " </select>\n" + " </form>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final Actions actions = new Actions(driver); actions.moveToElement(driver.findElement(By.id("select1"))); actions.perform(); Thread.sleep(400); assertTitle(driver, getExpectedAlerts()[0]); }
Example 7
Source File: HTMLSelectElementTest.java From htmlunit with Apache License 2.0 | 5 votes |
/** * @throws Exception if an error occurs */ @Test @Alerts(DEFAULT = "", FF = "mouse over", FF68 = "mouse over", FF60 = "mouse over") @BuggyWebDriver(FF = "mouse overmouse overmouse over", FF68 = "mouse overmouse overmouse over", FF60 = "mouse overmouse overmouse over") public void mouseOverDisabledSelect() throws Exception { final String html = "<html>\n" + " <head>\n" + " <script>\n" + " function doTest() {\n" + " document.title += 'mouse over';\n" + " }\n" + " </script>\n" + " </head>\n" + "<body>\n" + " <form id='form1'>\n" + " <select name='select1' id='select1' size='4' onmouseover='doTest()' disabled='disabled'>\n" + " <option value='option1' id='option1'>Option1</option>\n" + " <option value='option2' id='option2'>Option2</option>\n" + " </select>\n" + " </form>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final Actions actions = new Actions(driver); actions.moveToElement(driver.findElement(By.id("select1"))); actions.perform(); Thread.sleep(400); assertTitle(driver, getExpectedAlerts()[0]); }
Example 8
Source File: LibraryControlCheckboxDefaultAft.java From rice with Educational Community License v2.0 | 5 votes |
protected void actionSendKeysArrowDown(String id) { Actions actions = new Actions(driver); actions.moveToElement(driver.findElement(By.id(id))); actions.click(); actions.sendKeys(Keys.ARROW_DOWN); actions.build().perform(); }
Example 9
Source File: HTMLElement2Test.java From htmlunit with Apache License 2.0 | 5 votes |
/** * @throws Exception if an error occurs */ @Test @Alerts({"clicked", "fireEvent not available"}) public void fireEvent_WithoutTemplate() throws Exception { final String html = "<html>\n" + " <head>\n" + " <title>Test</title>\n" + " <script>\n" + " function doTest() {\n" + " var elem = document.getElementById('a');\n" + " if (!elem.fireEvent) { alert('fireEvent not available'); return }\n" + " elem.fireEvent('onclick');\n" + " }\n" + " </script>\n" + " </head>\n" + "<body>\n" + " <div id='a' onclick='alert(\"clicked\")'>foo</div>\n" + " <div id='b' onmouseover='doTest()'>bar</div>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); driver.findElement(By.id("a")).click(); verifyAlerts(driver, getExpectedAlerts()[0]); final Actions actions = new Actions(driver); actions.moveToElement(driver.findElement(By.id("b"))); actions.perform(); verifyAlerts(driver, getExpectedAlerts()[1]); }
Example 10
Source File: BrowserManager.java From BHBot with GNU General Public License v3.0 | 5 votes |
synchronized void moveMouseToPos(int x, int y) { try { Actions act = new Actions(driver); Point movePos = getChromeOffset(x, y); act.moveToElement(game, movePos.x, movePos.y); act.perform(); } catch (Exception e) { // do nothing } }
Example 11
Source File: BrowserManager.java From BHBot with GNU General Public License v3.0 | 5 votes |
synchronized void clickInGame(int x, int y) { Point clickCoordinates = getChromeOffset(x, y); Point awayCoordinates = getChromeOffset(0, 0); Actions act = new Actions(driver); act.moveToElement(game, clickCoordinates.x, clickCoordinates.y); act.click(); // so that the mouse doesn't stay on the button, for example. Or else button will be highlighted and cue won't get detected! act.moveToElement(game, awayCoordinates.x, awayCoordinates.y); act.perform(); }
Example 12
Source File: HTMLButtonElementTest.java From htmlunit with Apache License 2.0 | 4 votes |
/** * @throws Exception if an error occurs */ @Test @Alerts(DEFAULT = "Test:", FF = "Test:mouse over [disabledBtn]", FF68 = "Test:mouse over [disabledBtn]", FF60 = "Test:mouse over [disabledBtn]") public void mouseOverDiabled() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + " <head>\n" + " <title>Test:</title>\n" + " <script>\n" + " function dumpEvent(event) {\n" + " // target\n" + " var eTarget;\n" + " if (event.target) {\n" + " eTarget = event.target;\n" + " } else if (event.srcElement) {\n" + " eTarget = event.srcElement;\n" + " }\n" + " // defeat Safari bug\n" + " if (eTarget.nodeType == 3) {\n" + " eTarget = eTarget.parentNode;\n" + " }\n" + " var msg = 'mouse over';\n" + " if (eTarget.name) {\n" + " msg = msg + ' [' + eTarget.name + ']';\n" + " } else {\n" + " msg = msg + ' [' + eTarget.id + ']';\n" + " }\n" + " document.title += msg;\n" + " }\n" + " </script>\n" + " </head>\n" + "<body>\n" + " <form id='form1'>\n" + " <button id='disabledBtn' onmouseover='dumpEvent(event);' disabled>disabled button</button><br>\n" + " </form>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final Actions actions = new Actions(driver); actions.moveToElement(driver.findElement(By.id("disabledBtn"))); actions.perform(); assertTitle(driver, getExpectedAlerts()[0]); }
Example 13
Source File: RepositoryAdminTest.java From archiva with Apache License 2.0 | 4 votes |
@Test public void testManagedRepository() { // login( getAdminUsername(), getAdminPassword() ); WebDriverWait wait = new WebDriverWait(getWebDriver(), 20); WebElement el; el = wait.until(ExpectedConditions.elementToBeClickable(By.id("menu-repositories-list-a"))); tryClick( el, ExpectedConditions.presenceOfElementLocated( By.id( "managed-repositories-view-a" ) ), "Managed Repositories not activated"); el = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@href='#remote-repositories-content']"))); tryClick(el,ExpectedConditions.visibilityOfElementLocated(By.xpath("//table[@id='remote-repositories-table']//td[contains(text(),'central')]")), "Remote Repositories View not available"); el = wait.until(ExpectedConditions.elementToBeClickable( By.xpath("//a[@href='#remote-repository-edit']") )); el = tryClick(el, ExpectedConditions.visibilityOfElementLocated(By.id("remote-repository-save-button")), "Repository Save Button not available"); setFieldValue( "id", "myrepoid" ); setFieldValue( "name", "My repo name" ); setFieldValue( "url", "http://www.repo.org" ); el = wait.until( ExpectedConditions.elementToBeClickable(By.id("remote-repository-save-button") )); Actions actions = new Actions(getWebDriver()); actions.moveToElement(el); actions.perform(); ((JavascriptExecutor)getWebDriver()).executeScript("arguments[0].scrollIntoView();", el); el.click(); el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("remote-repositories-view-a"))); ((JavascriptExecutor)getWebDriver()).executeScript("arguments[0].scrollIntoView();", el); tryClick(By.id("menu-proxy-connectors-list-a"), ExpectedConditions.visibilityOfElementLocated(By.id("proxy-connectors-view-tabs-a-network-proxies-grid")), "Network proxies not available", 3,10 ); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("main-content"), "Proxy Connectors")); // proxy connect wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("proxy-connectors-view"), "central" )); assertTextNotPresent( "myrepoid" ); el = wait.until(ExpectedConditions.elementToBeClickable( By.id("proxy-connectors-view-tabs-a-edit") )); el.click(); el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("proxy-connector-btn-save"))); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("remote-repository-edit-fieldset"))); // Another hack, don't know why the normal selectValue() does not work here ((JavascriptExecutor)getWebDriver()).executeScript("jQuery('#sourceRepoId').css('display','block')"); Select select = new Select(getWebDriver().findElement(By.xpath(".//select[@id='sourceRepoId']"))); select.selectByVisibleText("internal"); // selectValue( "sourceRepoId", "internal", true ); // Workaround // TODO: Check after upgrade of htmlunit, bootstrap or jquery // TODO: Check whats wrong here ( (JavascriptExecutor) getWebDriver() ).executeScript( "$('#targetRepoId').show();" ); // End of Workaround wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("targetRepoId"))); selectValue( "targetRepoId", "myrepoid" ); el.click(); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("user-messages"),"ProxyConnector added")); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("proxy-connectors-view"), "central" )); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("proxy-connectors-view"), "myrepoid" )); tryClick(By.xpath("//i[contains(@class,'icon-resize-vertical')]//ancestor::a" ), ExpectedConditions.visibilityOfAllElementsLocatedBy(By.id("proxy-connector-edit-order-div")), "Edit order view not visible", 3, 10); // clickLinkWithXPath( "//i[contains(@class,'icon-resize-vertical')]//ancestor::a"); // This is needed here for HTMLUnit Tests. Currently do not know why, wait is not working for the // list entries down // waitPage(); // el = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("proxy-connector-edit-order-div"))); assertTextPresent( "internal" ); List<WebElement> repos = wait.until(ExpectedConditions.numberOfElementsToBe( By.xpath("//div[@id='proxy-connector-edit-order-div']/div"), 2)); Assert.assertTrue("First repo is myrepo", repos.get(0).getText().contains("myrepoid")); Assert.assertTrue("Second repo is central", repos.get(1).getText().contains("central")); // works until this point /*getSelenium().mouseDown( "xpath=//div[@id='proxy-connector-edit-order-div']/div[1]" ); getSelenium().mouseMove( "xpath=//div[@id='proxy-connector-edit-order-div']/div[2]" ); getSelenium().mouseUp( "xpath=//div[@id='proxy-connector-edit-order-div']/div[last()]" ); Assert.assertTrue( "Second repo is myrepo", getSelenium().getText("xpath=//div[@id='proxy-connector-edit-order-div']/div[2]" ).contains( "myrepoid" )); Assert.assertTrue( "First repo is central", getSelenium().getText("xpath=//div[@id='proxy-connector-edit-order-div']/div[1]" ).contains( "central" )); */ }
Example 14
Source File: WebDriverAftBase.java From rice with Educational Community License v2.0 | 4 votes |
/** * {@link org.openqa.selenium.interactions.Actions#moveToElement(org.openqa.selenium.WebElement)} * @param by */ public void fireMouseOverEvent(By by) { Actions builder = new Actions(driver); Actions hover = builder.moveToElement(findElement(by)); hover.perform(); }
Example 15
Source File: HTMLButtonElementTest.java From htmlunit with Apache License 2.0 | 4 votes |
/** * @throws Exception if an error occurs */ @Test @Alerts("mouse over [btn]") public void mouseOver() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + " <head>\n" + " <title>Test</title>\n" + " <script>\n" + " function dumpEvent(event) {\n" + " // target\n" + " var eTarget;\n" + " if (event.target) {\n" + " eTarget = event.target;\n" + " } else if (event.srcElement) {\n" + " eTarget = event.srcElement;\n" + " }\n" + " // defeat Safari bug\n" + " if (eTarget.nodeType == 3) {\n" + " eTarget = eTarget.parentNode;\n" + " }\n" + " var msg = 'mouse over';\n" + " if (eTarget.name) {\n" + " msg = msg + ' [' + eTarget.name + ']';\n" + " } else {\n" + " msg = msg + ' [' + eTarget.id + ']';\n" + " }\n" + " alert(msg);\n" + " }\n" + " </script>\n" + " </head>\n" + "<body>\n" + " <form id='form1'>\n" + " <button id='btn' onmouseover='dumpEvent(event);'>button</button><br>\n" + " </form>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final Actions actions = new Actions(driver); actions.moveToElement(driver.findElement(By.id("btn"))); actions.perform(); verifyAlerts(driver, getExpectedAlerts()); }
Example 16
Source File: HTMLOptionElement2Test.java From htmlunit with Apache License 2.0 | 4 votes |
/** * @throws Exception if an error occurs */ @Test @Alerts(DEFAULT = "", FF = "s-mouse over [select1] o-mouse over [option1] s-mouse over [option1]", FF68 = "s-mouse over [select1] o-mouse over [option1] s-mouse over [option1]", FF60 = "s-mouse over [select1] o-mouse over [option1] s-mouse over [option1]") public void mouseOverDisabledOption() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + " <head>\n" + " <title></title>\n" + " <script>\n" + " function dumpEvent(event, pre) {\n" + " // target\n" + " var eTarget;\n" + " if (event.target) {\n" + " eTarget = event.target;\n" + " } else if (event.srcElement) {\n" + " eTarget = event.srcElement;\n" + " }\n" + " // defeat Safari bug\n" + " if (eTarget.nodeType == 3) {\n" + " eTarget = eTarget.parentNode;\n" + " }\n" + " var msg = pre + '-mouse over';\n" + " if (eTarget.name) {\n" + " msg = msg + ' [' + eTarget.name + ']';\n" + " } else {\n" + " msg = msg + ' [' + eTarget.id + ']';\n" + " }\n" + " if (msg.length == 0) { msg = '-' };\n" + " document.title += ' ' + msg;\n" + " }\n" + " </script>\n" + " </head>\n" + "<body>\n" + " <form id='form1'>\n" + " <select name='select1' id='select1' size='2' onmouseover='dumpEvent(event, \"s\");' >\n" + " <option value='option1' id='option1' onmouseover='dumpEvent(event, \"o\");' " + "disabled='disabled'>Option1</option>\n" + " <option value='option2' id='option2'>Option2</option>\n" + " </select>\n" + " </form>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final Actions actions = new Actions(driver); actions.moveToElement(driver.findElement(By.id("option1"))); actions.perform(); assertTitle(driver, getExpectedAlerts()[0]); }
Example 17
Source File: HTMLOptionElement2Test.java From htmlunit with Apache License 2.0 | 4 votes |
/** * @throws Exception if an error occurs */ @Test @Alerts(DEFAULT = "o-mouse over [option1]", FF = "o-mouse over [option1] s-mouse over [option1]", FF68 = "o-mouse over [option1] s-mouse over [option1]", FF60 = "o-mouse over [option1] s-mouse over [option1]", IE = "") public void mouseOverDisabledSelect() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + " <head>\n" + " <script>\n" + " function dumpEvent(event, pre) {\n" + " // target\n" + " var eTarget;\n" + " if (event.target) {\n" + " eTarget = event.target;\n" + " } else if (event.srcElement) {\n" + " eTarget = event.srcElement;\n" + " }\n" + " // defeat Safari bug\n" + " if (eTarget.nodeType == 3) {\n" + " eTarget = eTarget.parentNode;\n" + " }\n" + " var msg = pre + '-mouse over';\n" + " if (eTarget.name) {\n" + " msg = msg + ' [' + eTarget.name + ']';\n" + " } else {\n" + " msg = msg + ' [' + eTarget.id + ']';\n" + " }\n" + " document.title += ' ' + msg;\n" + " }\n" + " </script>\n" + " </head>\n" + "<body>\n" + " <form id='form1'>\n" + " <select name='select1' id='select1' size='2' disabled='disabled' " + "onmouseover='dumpEvent(event, \"s\");' >\n" + " <option value='option1' id='option1' onmouseover='dumpEvent(event, \"o\");'>Option1</option>\n" + " <option value='option2' id='option2'>Option2</option>\n" + " </select>\n" + " </form>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final Actions actions = new Actions(driver); actions.moveToElement(driver.findElement(By.id("option1"))); actions.perform(); assertTitle(driver, getExpectedAlerts()[0]); }
Example 18
Source File: HTMLOptionElement2Test.java From htmlunit with Apache License 2.0 | 4 votes |
/** * @throws Exception if an error occurs */ @Test @Alerts(DEFAULT = {"o-mouse over [option1]", "s-mouse over [option1]"}, IE = {}) public void mouseOver() throws Exception { shutDownRealIE(); final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + " <head>\n" + " <title>Test</title>\n" + " <script>\n" + " function dumpEvent(event, pre) {\n" + " // target\n" + " var eTarget;\n" + " if (event.target) {\n" + " eTarget = event.target;\n" + " } else if (event.srcElement) {\n" + " eTarget = event.srcElement;\n" + " }\n" + " // defeat Safari bug\n" + " if (eTarget.nodeType == 3) {\n" + " eTarget = eTarget.parentNode;\n" + " }\n" + " var msg = pre + '-mouse over';\n" + " if (eTarget.name) {\n" + " msg = msg + ' [' + eTarget.name + ']';\n" + " } else {\n" + " msg = msg + ' [' + eTarget.id + ']';\n" + " }\n" + " alert(msg);\n" + " }\n" + " </script>\n" + " </head>\n" + "<body>\n" + " <form id='form1'>\n" + " <select name='select1' id='select1' size='2' onmouseover='dumpEvent(event, \"s\");' >\n" + " <option value='option1' id='option1' onmouseover='dumpEvent(event, \"o\");' >Option1</option>\n" + " <option value='option2' id='option2'>Option2</option>\n" + " </select>\n" + " </form>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final Actions actions = new Actions(driver); actions.moveToElement(driver.findElement(By.id("option1"))); actions.perform(); verifyAlerts(driver, getExpectedAlerts()); }
Example 19
Source File: HTMLTextAreaElementTest.java From htmlunit with Apache License 2.0 | 4 votes |
private void mouseOver(final String element) throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + " <head>\n" + " <script>\n" + " function dumpEvent(event) {\n" + " // target\n" + " var eTarget;\n" + " if (event.target) {\n" + " eTarget = event.target;\n" + " } else if (event.srcElement) {\n" + " eTarget = event.srcElement;\n" + " }\n" + " // defeat Safari bug\n" + " if (eTarget.nodeType == 3) {\n" + " eTarget = eTarget.parentNode;\n" + " }\n" + " var msg = 'mouse over';\n" + " if (eTarget.name) {\n" + " msg = msg + ' [' + eTarget.name + ']';\n" + " } else {\n" + " msg = msg + ' [' + eTarget.id + ']';\n" + " }\n" + " document.title += msg;\n" + " }\n" + " </script>\n" + " </head>\n" + "<body>\n" + " <form id='form1'>\n" + " " + element + "\n" + " </form>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final Actions actions = new Actions(driver); actions.moveToElement(driver.findElement(By.id("tester"))); actions.perform(); assertTitle(driver, getExpectedAlerts()[0]); }
Example 20
Source File: HTMLInputElementTest.java From htmlunit with Apache License 2.0 | 4 votes |
private void mouseOver(final String element) throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + " <head>\n" + " <script>\n" + " function dumpEvent(event) {\n" + " // target\n" + " var eTarget;\n" + " if (event.target) {\n" + " eTarget = event.target;\n" + " } else if (event.srcElement) {\n" + " eTarget = event.srcElement;\n" + " }\n" + " // defeat Safari bug\n" + " if (eTarget.nodeType == 3) {\n" + " eTarget = eTarget.parentNode;\n" + " }\n" + " var msg = 'mouse over';\n" + " if (eTarget.name) {\n" + " msg = msg + ' [' + eTarget.name + ']';\n" + " } else {\n" + " msg = msg + ' [' + eTarget.id + ']';\n" + " }\n" + " document.title+= msg;\n" + " }\n" + " </script>\n" + " </head>\n" + "<body>\n" + " <form id='form1'>\n" + " " + element + "\n" + " </form>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final Actions actions = new Actions(driver); actions.moveToElement(driver.findElement(By.id("tester"))); actions.perform(); assertTitle(driver, getExpectedAlerts()[0]); }