3 回答

TA貢獻1831條經驗 獲得超10個贊
可能您想使用get_attributeinsted of .text。文檔在這里。
elements = driver.find_elements_by_xpath('/html/body/ui-view/main/div[1]/ui-view/version[2]/div/section/section/section/race-list/ul/li[1]/a')
for e in elements:
print(e.get_attribute("href"))

TA貢獻1825條經驗 獲得超4個贊
/racing/2020-07-31/MACKAY/MAC/R/8HTML 中的值是href屬性的值而不是innerText.
解決方案
而不是使用您需要使用的文本get_attribute("href")屬性,有效的代碼行將是:
elements = driver.find_elements_by_xpath('/html/body/ui-view/main/div[1]/ui-view/version[2]/div/section/section/section/race-list/ul/li[1]/a')
for e in elements:
print(e.get_attribute("href"))

TA貢獻1840條經驗 獲得超5個贊
是的,您可以根據需要使用getAttribute(attributeLocator)函數。
selenium.getAttribute(//xpath@href);
指定您需要知道其類別的元素的 Xpath。
添加回答
舉報