Examples of Selenium

  • link=textPattern: Select the link (anchor) element which contains text matching the specified pattern.
  • css=cssSelectorSyntax: Select the element using css selectors. Please refer to CSS2 selectors, CSS3 selectors for more information. You can also check the TestCssLocators test in the selenium test suite for an example of usage, which is included in the downloaded selenium core package.

    Currently the css selector locator supports all css1, css2 and css3 selectors except namespace in css3, some pseudo classes(:nth-of-type, :nth-last-of-type, :first-of-type, :last-of-type, :only-of-type, :visited, :hover, :active, :focus, :indeterminate) and pseudo elements(::first-line, ::first-letter, ::selection, ::before, ::after).

  • Without an explicit locator prefix, Selenium uses the following default strategies:

    Element Filters

    Element filters can be used with a locator to refine a list of candidate elements. They are currently used only in the 'name' element-locator.

    Filters look much like locators, ie.

    filterType=argument

    Supported element-filters are:

    value=valuePattern

    Matches elements based on their values. This is particularly useful for refining a list of similarly-named toggle-buttons.

    index=index

    Selects a single element based on its position in the list (offset from zero).

    String-match Patterns

    Various Pattern syntaxes are available for matching string values:

    If no pattern prefix is specified, Selenium assumes that it's a "glob" pattern.

    For commands that return multiple values (such as verifySelectOptions), the string being matched is a comma-separated list of the return values, where both commas and backslashes in the values are backslash-escaped. When providing a pattern, the optional matching syntax (i.e. glob, regexp, etc.) is specified once, as usual, at the beginning of the pattern.


    Examples of com.thoughtworks.selenium.Selenium

        /*test entire TreeTable*/
        //TODO Dont't work warn
         @Test
        public void testCommonTreeTableEvents() {
            Selenium selenium = getSelenium();
            testAppFunctionalPage("/components/treetable/treeTable_events.jsf");

            //onfocus
            assertTrue(selenium.isTextPresent("onfocus works"));
            //todo: uncomment if JSFC-1453 fixed
            //assertTrue(selenium.isTextPresent("focus"));

            ElementInspector treeTable = element("fn:eventsTreeTable");
            //onclick
            treeTable.click();
            assertTrue(selenium.isTextPresent("onclick works"));
            assertTrue(selenium.isTextPresent("click"));

            //onblur
            //todo: selenium can set focus to the several page elements in own FF instance, so event not fired. Problem unresolved yet.
    /*    assertTrue(selenium.isTextPresent("onblur works"));
        assertTrue(selenium.isTextPresent("blur"));*/

            //ondblclick
            treeTable.doubleClick();
            assertTrue(selenium.isTextPresent("ondblclick works"));
            assertTrue(selenium.isTextPresent("dblclick"));

            //onkeydown
            treeTable.keyDown(KeyEvent.VK_DOWN);
            assertTrue(selenium.isTextPresent("onkeydown works"));
            assertTrue(selenium.isTextPresent("keydown"));

            //onkeypress
            treeTable.keyPress(KeyEvent.VK_DOWN);
            assertTrue(selenium.isTextPresent("onkeypress works"));
            assertTrue(selenium.isTextPresent("keypress"));

            //onkeyup
            treeTable.keyUp(KeyEvent.VK_DOWN);
            assertTrue(selenium.isTextPresent("onkeyup works"));
            assertTrue(selenium.isTextPresent("keyup"));

            //onmousedown
            treeTable.mouseDown();
            assertTrue(selenium.isTextPresent("onmousedown works"));
            assertTrue(selenium.isTextPresent("mousedown"));

            //onmouseout
            treeTable.mouseOut();
            assertTrue(selenium.isTextPresent("onmouseout works"));
            assertTrue(selenium.isTextPresent("mouseout"));

            //onmouseover
            treeTable.mouseOver();
            assertTrue(selenium.isTextPresent("onmouseover works"));
            assertTrue(selenium.isTextPresent("mouseover"));

            //onmouseup
            treeTable.mouseOver();
            assertTrue(selenium.isTextPresent("onmouseover works"));
            assertTrue(selenium.isTextPresent("mouseover"));

            //onmousemove
            element("fn:mousemoveTreeTable").mouseMove();
            assertTrue(selenium.isTextPresent("onmousemove works"));
            assertTrue(selenium.isTextPresent("mousemove"));

        }
    View Full Code Here
    TOP
    Copyright © 2018 www.massapi.com. All rights reserved.
    All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.