DOM樹,使用xpath獲取元素 document.evaluate



select_js = """ function getElementByXpath(path) { return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; } ele = getElementByXpath(arguments[0]); ele.readOnly = false; ele.value = arguments[1]; """ driver.execute_script(select_js, "//select[@id='Agency']/following-sibling::div//input",'推薦機構會員20190715')
# 自定義函數getElementByXpath(),通過傳入xpath路徑獲取元素。
function getElementByXpath(path) {
  return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM