XPath 정보, CSS Selector 와 XPath
//-------------------------------------
[ HTML ]
<div class="c1 c2"> ... </div>
//-------------------------------------
[ XPath ]
*[contains(@class,"c1")]
*[contains(@class,"c1 c2")]
*[contains(@class,"c2 c1")] <== 에러! 순서바뀌면 안됨
- 클래스가 2개의 이름을 가졌는데 이름 순서에 상관없이 검색 (복잡)
*[contains(concat(' ', normalize-space(@class), ' '), ' c1 ') and contains(concat(' ', normalize-space(@class), ' '), ' c2 ')]
//-----------------------------------------------------------------------------
CSS Selector 를 XPath로 변환
[ CSS Selector ]
p div#id1 span#id2.cl1.cl2 .cl3-2
[ XPath ]
//p//div[@id='id1']//span[@id='id2'][contains(concat(' ', normalize-space(@class), ' '), ' cl1 ')][contains(concat(' ', normalize-space(@class), ' '), ' cl2 ')]//*[contains(concat(' ', normalize-space(@class), ' '), ' cl3-2 ')]
//-----------------------------------------------------------------------------
// 참고
* XPath Syntax
https://www.w3schools.com/xml/xpath_syntax.asp
* How to Choose Selectors for Automation to Make Your Life a Whole Lot Easier
https://exadel.com/news/how-to-choose-selectors-for-automation-to-make-your-life-a-whole-lot-easier/
* CSS2XPath
https://css2xpath.github.io/
- 결과물에 에러 있음