首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > CSS >

selenium 进阶二: CSS SELECTOR 的完整版

2012-10-26 
selenium 进阶2: CSS SELECTOR 的完整版。根据 最全面的官方文档: http://release.seleniumhq.org/selenium

selenium 进阶2: CSS SELECTOR 的完整版。

根据 最全面的官方文档: http://release.seleniumhq.org/selenium-core/1.0.1/reference.html

?

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.

    ?

    http://code.google.com/p/selenium/source/browse/trunk/selenium/test/java/com/thoughtworks/selenium/corebased/TestCssLocators.java?r=10587

    ?

    package com.thoughtworks.selenium.corebased;import com.thoughtworks.selenium.InternalSelenseTestNgBase;import org.testng.annotations.Test;public class TestCssLocators extends InternalSelenseTestNgBase {@Test public void testCssLocators() throws Exception {//         Unimplemented features://             namespace//             pseudo element//                 ::first-line//                 ::first-letter//                 ::selection//                 ::before//                 ::after//             pseudo class including://                 :nth-of-type//                 :nth-last-of-type//                 :first-of-type//                 :last-of-type//                 :only-of-type//                 :visited//                 :hover//                 :active//                 :focus//                 :indeterminate//         selenium.open("../tests/html/test_locators.html");// css2 selector test// universal selectorverifyTrue(selenium.isElementPresent("css=*"));// only element typeverifyEquals(selenium.getText("css=p"), "this is the first element in the document");verifyEquals(selenium.getText("css=a"), "this is the first element");// id selectorverifyEquals(selenium.getText("css=a#id3"), "this is the third element");// attribute selectorverifyTrue(selenium.isElementPresent("css=input[name]"));verifyEquals(selenium.getText("css=a[href="#id3"]"), "this is the third element");verifyFalse(selenium.isElementPresent("css=span[selenium:foo]"));verifyEquals(selenium.getText("css=a[class~="class2"]"), "this is the fifth element");verifyEquals(selenium.getText("css=a[lang|="en"]"), "this is the sixth element");// class selectorverifyTrue(selenium.isElementPresent("css=a.a1"));// pseudo class selectorverifyEquals(selenium.getText("css=th:first-child"), "theHeaderText");verifyEquals(selenium.getText("css=a:lang(en)"), "this is the first element");verifyEquals(selenium.getText("css=#linkPseudoTest :link"), "link pseudo test");// descendant combinatorverifyEquals(selenium.getText("css=div#combinatorTest a"), "and grandson");// child combinatorverifyEquals(selenium.getText("css=div#combinatorTest > span"), "this is a child and grandson");// preceding combinatorverifyEquals(selenium.getText("css=span#firstChild + span"), "another child");// css3 selector test// attribuite testverifyEquals(selenium.getText("css=a[name^="foo"]"), "foobar");verifyEquals(selenium.getText("css=a[name$="foo"]"), "barfoo");verifyEquals(selenium.getText("css=a[name*="zoo"]"), "foozoobar");verifyEquals(selenium.getText("css=a[name*="name"][alt]"), "this is the second element");// pseudo class testverifyTrue(selenium.isElementPresent("css=html:root"));verifyEquals(selenium.getText("css=div#structuralPseudo :nth-child(2n)"), "span2");verifyEquals(selenium.getText("css=div#structuralPseudo :nth-child(2)"), "span2");verifyEquals(selenium.getText("css=div#structuralPseudo :nth-child(-n+6)"), "span1");verifyEquals(selenium.getText("css=div#structuralPseudo :nth-last-child(4n+1)"), "span4");verifyEquals(selenium.getText("css=div#structuralPseudo :nth-last-child(2)"), "div3");verifyEquals(selenium.getText("css=div#structuralPseudo :nth-last-child(-n+6)"), "span3");verifyEquals(selenium.getText("css=div#structuralPseudo :first-child"), "span1");verifyEquals(selenium.getText("css=div#structuralPseudo :last-child"), "div4");verifyEquals(selenium.getText("css=div#onlyChild span:only-child"), "only child");verifyTrue(selenium.isElementPresent("css=span:empty"));verifyEquals(selenium.getText("css=div#targetTest span:target"), "target");verifyTrue(selenium.isElementPresent("css=input[type="text"]:enabled"));verifyTrue(selenium.isElementPresent("css=input[type="text"]:disabled"));verifyTrue(selenium.isElementPresent("css=input[type="checkbox"]:checked"));verifyEquals(selenium.getText("css=a:contains("zoo")"), "foozoobar");verifyEquals(selenium.getText("css=div#structuralPseudo span:not(:first-child)"), "span2");verifyEquals(selenium.getText("css=div#structuralPseudo :not(span):not(:last-child)"), "div1");// combinator testverifyEquals(selenium.getText("css=div#combinatorTest span#firstChild ~ span"), "another child");}}

热点排行