Style
This commit is contained in:
parent
d4ea9b9473
commit
ada5cf67b4
|
@ -92,11 +92,12 @@
|
||||||
h2 {
|
h2 {
|
||||||
margin-top: 3em;
|
margin-top: 3em;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pre {
|
pre {
|
||||||
background: #fafafa;
|
border-right: solid 1px #eef3fa;
|
||||||
border-bottom: solid 1px #eef3fa;
|
border-bottom: solid 1px #c7d7ee;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
135
xpath.md
135
xpath.md
|
@ -5,90 +5,85 @@ layout: default
|
||||||
|
|
||||||
### Descendant selectors
|
### Descendant selectors
|
||||||
|
|
||||||
| CSS | Xpath | ? |
|
| CSS | Xpath | ? |
|
||||||
| --- | --- | ---: |
|
| ---- | ---- | -- |
|
||||||
| `h1` | `//h1` | [?](#prefixes) |
|
| `h1` | `//h1` | [?](#prefixes) |
|
||||||
| `div p` | `//div//p` | [?](#axes) |
|
| `div p` | `//div//p` | [?](#axes) |
|
||||||
| --- | --- | |
|
| `ul > li` | `//ul/li` | [?](#axes) |
|
||||||
| `ul > li` | `//ul/li` | [?](#axes) |
|
| `ul > li > a` | `//ul/li/a` | |
|
||||||
| `ul > li > a` | `//ul/li/a` | |
|
| `div > *` | `//div/*` | |
|
||||||
| `div > *` | `//div/*` | |
|
| ---- | ---- | -- |
|
||||||
| --- | --- | |
|
| `:root` | `/` | [?](#prefixes) |
|
||||||
| `:root` | `/` | [?](#prefixes) |
|
| `:root > body` | `/body` | |
|
||||||
| `:root > body` | `/body` | |
|
{:.greycode.no-head.xp}
|
||||||
{:.greycode.no-head}
|
|
||||||
|
|
||||||
### Attribute selectors
|
### Attribute selectors
|
||||||
|
|
||||||
| CSS | Xpath | ? |
|
| CSS | Xpath | ? |
|
||||||
| --- | --- | --: |
|
| ---- | ---- | -- |
|
||||||
| `#id` | `//[@id="id"]` | [?](#predicates) |
|
| `#id` | `//[@id="id"]` | [?](#predicates) |
|
||||||
| `.class` | `//[@class="class"]` *...[kinda](#class-check)* | |
|
| `.class` | `//[@class="class"]` *...[kinda](#class-check)* | |
|
||||||
| `input[type="submit"]` | `//input[@type="submit"]` | |
|
| `input[type="submit"]` | `//input[@type="submit"]` | |
|
||||||
| `a#abc[for="xyz"]` | `//a[@id="abc"][@for="xyz"]` | [?](#chaining-order) |
|
| `a#abc[for="xyz"]` | `//a[@id="abc"][@for="xyz"]` | [?](#chaining-order) |
|
||||||
| --- | --- | |
|
| `a[rel]` | `//a[@rel]` | |
|
||||||
| `a[rel]` | `//a[@rel]` | |
|
| ---- | ---- | -- |
|
||||||
| --- | --- | |
|
| `a[href^='/']` | `//a[starts-with(@href, '/')]` | [?](#string-functions) |
|
||||||
| `a[href^='/']` | `//a[starts-with(@href, '/')]` | [?](#string-functions) |
|
| `a[href$='pdf']` | `//a[ends-with(@href, '.pdf')]` | |
|
||||||
| `a[href$='pdf']` | `//a[ends-with(@href, '.pdf')]` | |
|
| `a[href~='://']` | `//a[contains(@href, '://')]` *...[kinda](#class-check)* | |
|
||||||
| `a[href~='://']` | `//a[contains(@href, '://')]` *...[kinda](#class-check)* | |
|
{:.greycode.no-head.xp}
|
||||||
{:.greycode.no-head}
|
|
||||||
|
|
||||||
### Order selectors
|
### Attribute selectors
|
||||||
|
|
||||||
| CSS | Xpath | ? |
|
| CSS | Xpath | ? |
|
||||||
| --- | --- | --: |
|
| ---- | ---- | -- |
|
||||||
| `ul > li:first-child` | `//ul/li[1]` | [?](#indexing) |
|
| `ul > li:first-child` | `//ul/li[1]` | [?](#indexing) |
|
||||||
| `ul > li:nth-child(2)` | `//ul/li[2]` | |
|
| `ul > li:nth-child(2)` | `//ul/li[2]` | |
|
||||||
| `ul > li:last-child` | `//ul/li[last()]` | |
|
| `ul > li:last-child` | `//ul/li[last()]` | |
|
||||||
| --- | --- | |
|
| `li#id:first-child` | `//li[@id="id"][1]` | |
|
||||||
| `li#id:first-child` | `//li[@id="id"][1]` | |
|
| `a:first-child` | `//a[1]` | |
|
||||||
| --- | --- | |
|
| `a:last-child` | `//a[last()]` | |
|
||||||
| `a:first-child` | `//a[1]` | |
|
{:.greycode.no-head.xp}
|
||||||
| `a:last-child` | `//a[last()]` | |
|
|
||||||
{:.greycode.no-head}
|
|
||||||
|
|
||||||
### Siblings
|
### Siblings
|
||||||
|
|
||||||
| CSS | Xpath | ? |
|
| CSS | Xpath | ? |
|
||||||
| --- | --- | --: |
|
| ---- | ---- | -- |
|
||||||
| `h1 ~ ul` | `//h1/following-sibling::ul` | [?](#other-axes) |
|
| `h1 ~ ul` | `//h1/following-sibling::ul` | [?](#other-axes) |
|
||||||
| `h1 + ul` | `//h1/following-sibling::ul[1]` | |
|
| `h1 + ul` | `//h1/following-sibling::ul[1]` | |
|
||||||
| --- | --- | |
|
| `h1 ~ #id` | `//h1/following-sibling::[@id="id"]` | |
|
||||||
| `h1 ~ #id` | `//h1/following-sibling::[@id="id"]` | |
|
{:.greycode.no-head.xp}
|
||||||
{:.greycode.no-head}
|
|
||||||
|
|
||||||
|
|
||||||
### Negation
|
|
||||||
|
|
||||||
| CSS | Xpath | ? |
|
|
||||||
| --- | --- | --: |
|
|
||||||
| `h1:not([id])` | `//h1[not(@id)]` | [?](#boolean-functions) |
|
|
||||||
{:.greycode.no-head}
|
|
||||||
|
|
||||||
### jQuery
|
### jQuery
|
||||||
|
|
||||||
| jQuery | Xpath | ? |
|
| CSS | Xpath | ? |
|
||||||
| ------ | --- | --: |
|
| ---- | ---- | -- |
|
||||||
| `$('ul > li').parent()` | `//ul/li/..` | [?](#other-axes) |
|
| `$('ul > li').parent()` | `//ul/li/..` | [?](#other-axes) |
|
||||||
| `$('li').closest('section')` | `//li/ancestor-or-self::section` | |
|
| `$('li').closest('section')` | `//li/ancestor-or-self::section` | |
|
||||||
| ---- | ---- | |
|
| `$('a').attr('href')` | `//a/@href` | [?](#steps) |
|
||||||
| `$('a').attr('href')` | `//a/@href` | [?](#steps) |
|
| `$('span').text()` | `//span/text()` | |
|
||||||
| `$('span').text()` | `//span/text()` | |
|
{:.greycode.no-head.xp}
|
||||||
{:.greycode.no-head}
|
|
||||||
|
|
||||||
### Other things
|
### Other things
|
||||||
|
|
||||||
| jQuery | Xpath | ? |
|
| CSS | Xpath | ? |
|
||||||
| ---- | ---- | -- |
|
| ---- | ---- | -- |
|
||||||
| Text match | `//button[text()="Submit"]` | [?](#operators) |
|
| `h1:not([id])` | `//h1[not(@id)]` | [?](#boolean-functions) |
|
||||||
| Text match (substring) | `//button[contains(text(),"Go")]` | |
|
| Text match | `//button[text()="Submit"]` | [?](#operators) |
|
||||||
| Arithmetic | `//product[@price > 2.50]` | |
|
| Text match (substring) | `//button[contains(text(),"Go")]` | |
|
||||||
| Has children | `//ul[*]` | |
|
| Arithmetic | `//product[@price > 2.50]` | |
|
||||||
| Has children (specific) | `//ul[li]` | |
|
| Has children | `//ul[*]` | |
|
||||||
| Or logic | `//a[@name or @href]` | [?](#operators) |
|
| Has children (specific) | `//ul[li]` | |
|
||||||
| Union (joins results) | `//a | //div` | [?](#unions) |
|
| Or logic | `//a[@name or @href]` | [?](#operators) |
|
||||||
{:.greycode.no-head}
|
| Union (joins results) | `//a | //div` | [?](#unions) |
|
||||||
|
{:.greycode.no-head.xp}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
/* ensure tables align */
|
||||||
|
table.xp {table-layout: fixed;}
|
||||||
|
table.xp tr>:nth-child(1) {width: 30%;}
|
||||||
|
table.xp tr>:nth-child(2) {width: auto;}
|
||||||
|
table.xp tr>:nth-child(3) {width: 10%; text-align:right;}
|
||||||
|
</style>
|
||||||
|
|
||||||
### Class check
|
### Class check
|
||||||
Xpath doesn't have the "check if part of space-separated list" operator, so this is the workaround ([source](http://pivotallabs.com/xpath-css-class-matching/)):
|
Xpath doesn't have the "check if part of space-separated list" operator, so this is the workaround ([source](http://pivotallabs.com/xpath-css-class-matching/)):
|
||||||
|
|
Loading…
Reference in New Issue