【问题标题】:printing a value using selenium python find_elements_by_xpath使用 selenium python find_elements_by_xpath 打印一个值
【发布时间】:2021-06-26 20:39:42
【问题描述】:

我正在尝试使用 selenium python 打印一个变量 (rel="3380.80") 值。

这是我的方法tree = driver.find_elements_by_xpath("/html/body/div[11]/div[1]/div[4]/div[1]/div/div[1]/div/div[1]/div[2]/rel")

打印(树)

<div id="nsecp" class="inprice1 nsecp" rel="3380.80" data-numberanimate-value="3,380.80" data-numberanimate-characterheight="65" data-numberanimate-characterwidth="31" data-numberanimate-animationtimes="[10,0,10]" style="display: inline-block; vertical-align: top; height: 65px;"><div data-numberanimate-pos="5" style="width: 31px; height: 65px; overflow: hidden; display: inline-block;">

【问题讨论】:

  • 到底是什么问题?
  • 无法打印 rel 值 @catalina

标签: python selenium automation


【解决方案1】:

那里只有 1 个元素具有 rel=3380.00 并且它还具有 id 属性。您可以通过id找到元素并获取属性rel。这是代码

el = driver.find_element_by_id('nsecp')
val = el.get_attribute("rel")

【讨论】:

    猜你喜欢
    • 2019-11-08
    • 1970-01-01
    • 2020-11-07
    • 2018-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-20
    • 2021-06-12
    相关资源
    最近更新 更多