【问题标题】:Retrieve the content of meta description from web-page using selenium webdriver使用 selenium webdriver 从网页中检索元描述的内容
【发布时间】:2014-11-16 09:56:33
【问题描述】:

想用webdriver获取页面元描述的内容。

假设,从下面的 DOM 想要检索文本 Test.com provides a complete software solution for creating online tests and managing enterprise and specialist certification programs, in up to 22 languages

<script src="content/js/jquery.min.js">
<meta content="Test.com provides a complete software solution for creating online tests and managing enterprise and specialist certification programs, in up to 22 languages." name="description">
<meta content="Test.com" name="keywords">

我试过了

System.out.println(driver.findElement(By.xpath("//meta[@name='description']")).getText());

但上面的代码对我不起作用。

【问题讨论】:

    标签: java selenium xpath selenium-webdriver webdriver


    【解决方案1】:

    您正在尝试获取属性值,因此请使用 getText() 代替 getAttribute()

    driver.findElement(By.xpath("//meta[@name='description']"))
          .getAttribute("content")
    

    【讨论】:

      【解决方案2】:

      你也可以试试

      driver.findElement(By.xpath("//*[@name='description']"))
            .getAttribute("content")
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-26
        • 1970-01-01
        • 2020-04-21
        • 1970-01-01
        • 1970-01-01
        • 2011-10-04
        • 2014-04-21
        相关资源
        最近更新 更多