반응형
ID 또는 클래스가없는 요소를 찾기위한 XPath
id 속성이없는 모든 tr 요소를 어떻게 사용할 수 있습니까?
<tr id="name">...</tr>
<tr>...</tr>
<tr>...</tr>
감사합니다
꽤 직설적 인 :
//tr[not(@id) and not(@class)]
그러면 및 속성 tr
이 모두없는 모든 요소가 제공 됩니다. 둘 중 하나가없는 모든 요소 를 원하면 대신 사용하십시오 .id
class
tr
or
and
//tr[not(@id) or not(@class)]
이런 식으로 속성과 요소를 사용할 때 속성이나 요소에 값이 있으면 참인 것처럼 처리합니다. 누락 된 경우 거짓 인 것처럼 처리됩니다.
당신이 요소를 소유하고있는 이 클래스는 a
하지만 하지 않는 클래스가 b
다음을 수행 할 수 있습니다.
//*[contains(@class, 'a') and not(contains(@class, 'b'))]
또는 부분 일치하지 않습니다.
//*[contains(concat(' ', normalize-space(@class), ' '), ' some-class ') and
not(contains(concat(' ', normalize-space(@class), ' '), ' another-class '))]
너 시도 할 수있어 //tr[not(@id)]?
if (elm.hasAttribute('id')) {
//if id - implement here
} else if (elm.hasAttribute('class')) {
//if class - implement here
} else {
for (i = 1, sib = elm.previousSibling; sib; sib = sib.previousSibling) {
if (sib.localName == elm.localName)
i++;
};
segs.unshift(elm.localName.toLowerCase() + '[' + i + ']');
}
참고 URL : https://stackoverflow.com/questions/2404130/xpath-to-find-elements-that-does-not-have-an-id-or-class
반응형
'ProgramingTip' 카테고리의 다른 글
(400) HTTP 잘못된 요청으로 인해 큰 WCF 웹 서비스 요청 실패 함 (0) | 2020.10.21 |
---|---|
git : "branchname"과 "refs / head / branchname"의 차이점 (0) | 2020.10.21 |
페이지를 다시로드하지 않고 javascript / jQuery를 사용하여 URL 또는 쿼리를 업데이트하는 방법은 무엇입니까? (0) | 2020.10.21 |
Android Studio의 기존 프로젝트에 새 활동을 추가하는 방법은 무엇입니까? (0) | 2020.10.21 |
CSV 파일에서 헤더가있는 PostgreSQL 테이블로 CSV 파일을 복사하는 방법은 무엇입니까? (0) | 2020.10.21 |