【问题标题】:Xpath unable to get the value from SPANXpath 无法从 SPAN 获取值
【发布时间】:2022-01-18 01:08:41
【问题描述】:

我试过这个,我得到空响应:

sample=driver.find_elements_by_xpath('/html/body/app-root/div/app-visual-code/div[3]/div[2]/div/div[3]/span[2]')
for elem in sample:
    test1=elem.text
    print(test1)

【问题讨论】:

  • 那个循环很奇怪。你还没有向我们展示test 是什么,循环变量elem 从未使用过......
  • 我假设你必须这样做:for elem in sample: test1=elem.text print(test1)
  • 我已经这样做了,对于 elem in test: test1=elem.text print(test1)

标签: python selenium-webdriver xpath selenium-chromedriver


【解决方案1】:

如果该跨度是唯一具有class="manual-code" 的跨度,那么您可以尝试使用更简单的 xpath 表达式,例如

sample=driver.find_elements_by_xpath(".//div[@class='manual-code-section']/span[@class='manual-code']")

【讨论】:

    猜你喜欢
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-04
    • 1970-01-01
    • 1970-01-01
    • 2013-03-31
    • 1970-01-01
    相关资源
    最近更新 更多