-1
如何查找所有a.href
innerHTML匹配的元素Page [\d]+
?selenium xpath使用正則表達式匹配找到帶有innerHTML的href
喜歡這個
<a href="/something">Page 1</a>
<a href="/something">Page 2</a>
<a href="/something">Page 97</a>
如何查找所有a.href
innerHTML匹配的元素Page [\d]+
?selenium xpath使用正則表達式匹配找到帶有innerHTML的href
喜歡這個
<a href="/something">Page 1</a>
<a href="/something">Page 2</a>
<a href="/something">Page 97</a>
有趣的解決方案是(如果你期待着某些HREF可以用「頁面」開始,包括之後沒有數字),以獲得使用此定位的所有元素:
driver.findElements(By.xPath("//a[@href][number(substring-after(text(), 'Page ')) > 0]"))
使用這個XPath爲您findElements撥打:
"//a[text()[contains(.,'Page')]]"
你的意思是像'//一個[開始 - 用( 「頁」。)'? – Andersson