java - 如何使用 HP UFT 或 Selenium Webriver 检索开放图形的元标记属性

标签 java selenium-webdriver qtp hp-uft

我正在尝试验证我们网站中的开放图元标记。 HTML 代码如下:

<div class="atg_store_applicationResourceContainer">
            </div>
      <meta name="robots" content="index, follow" />

            <!--  Coming inside regular metadetails-->
                            <!-- contentKey =  -->

        <!--  SEOTagID -  **** -->
    <title>Sectional Living Rooms&nbsp;</title>
                <meta name="description" content="Find Sectional Living Rooms&amp;nbsp; that will look great in your home and complement the rest of your furniture." />
                <meta name="author" content="EXAMPLE.com" />

        <meta name="google-site-verification" content="UscxdOsY5bXX9hk_Y0GILMPvzsL66vDcHHwkZZ7Gxpg" />

        <meta property="og:title" content="Sectional Living Rooms&nbsp;"/>
        <meta property="og:site_name" content="EXAMPLE"/>
            <!-- requestSocialUrl = http://www.example.com/cartridges/PageSlot/PageSlot.jsp -->
      <!-- customCanonical = http://www.example.com/furniture/Living-Rooms/Sectional-Living-Rooms/_/N-8wh -->
                       <link rel="canonical" href="http://www.example.com/furniture/Living-Rooms/Sectional-Living-Rooms/_/N-8wh" /> <!-- add + instead of space in words for SEO -->
                              <meta property="og:image" content="http:/images/unavailable.gif?$PDP_Cart_Primary_150x150$" />
            <meta property="og:type" content="product"/>
        <meta property="og:url" content="http://www.example.com/furniture/Living-Rooms/Sectional-Living-Rooms/_/N-8wh"/>
        <meta property="og:description" content="Find Sectional Living Rooms&amp;nbsp; that will look great in your home and complement the rest of your furniture.&amp;nbsp;#iSofa #abc"/>
    <script>var _adblock=true;</script>

我正在尝试获取 content 的值来自 meta 的属性具有 property 的标签属性值为 og:title & og:description 。任何帮助都会有帮助。

我能够找到带有名称的元内容,但无法获取 <og:title> 的内容& <og:description>因为标签没有名称

我们正在使用 UFT 和 Selenium Webdriver (Java)。这样我就可以在任何一个上使用帮助。

最佳答案

对于 Selenium,你可以使用 xpath 就像

//meta[@property='og:title']
//meta[@property='og:description']

要获取内容,请使用 WebElementgetAttribute() 方法

 WebElement titleEl=driver.findElement(By.xpath("//meta[@property='og:title']"));
 String titleContent = titleEl.getAttribute("content");

关于java - 如何使用 HP UFT 或 Selenium Webriver 检索开放图形的元标记属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38333147/

相关文章:

java - 如何将我的构建器对象复制到另一个对象并修改其中的几个字段?

java - 代码生成和反射

python - Selenium Steam 社区市场列表 python

testing - 如何使用 XPATH 访问 TR 内的链接

qtp - 如何根据当前报表节点获取运行结果状态?

vbscript - 使用QTP的自动化对象模型时,有什么方法可以显示QTP运行时的错误

java - 如何在 Java 中将 HTML 文本区域元素拆分为行数组

java - 在表中保留最新的 n 个条目

Python "with"语句 : __exit__() ignored

qtp - 恢复场景或在函数本身中处理大部分场景