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。
添加回答
举报