【问题标题】:splitting the outerHTML attribute in python在python中拆分outerHTML属性
【发布时间】:2014-01-27 16:27:38
【问题描述】:

我想从outerHTML 属性中分离出特定的文本以用于Web 链接。

while Id is true:
    link = driver.find_element_by_xpath("//a[@id='bu:ms:all-sp:2']")
    href = link.get_attribute("outerHTML")  
    link.click()
    # This will load the link in the same page !
    self.assertIn(href, self.page.get_current_url())

当我打印 href 时,输出将是,

<a id="bu:ms:all-sp:8" href="/euro/tennis" class="Pointer"><span class="SportImg8"></span> Tennis <span class="NumEvt">51</span></a>

我想将其拆分并单独使用当前 URL 断言 href (/euro/tennis) 的值。

有人可以帮我吗?

【问题讨论】:

    标签: python selenium attributes split


    【解决方案1】:

    获取href 属性而不是outerHTML

    href = link.get_attribute("href")  
    

    【讨论】:

      猜你喜欢
      • 2014-01-30
      • 1970-01-01
      • 2022-10-30
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多