selenium 进阶1: CSS SELECTOR
比如:找到页面中,找到一组 <a>, 然后再找到[2].parent()这个dom, jQuery得心应手,selenium 之前则只能借助于晦涩难懂的 xpath.? >_<
The CSS locator strategy uses CSS selectors to find the elements in the page. Selenium supports CSS 1 through 3 selectors syntax excepted CSS3 namespaces and the following:
pseudo-classespseudo-elements:nth-of-type
::first-line
:nth-last-of-type
::first-letter
:first-of-type
::selection
:last-of-type
::before
:only-of-type
::after
:visited
:hover
:active
:focus
:indeterminate
css=div[id="pancakes"] > button[value="Blueberry"]
selects the button with its value property set at Blueberry if children of the pancakes divPROS:
CONS: