如何获取 Adob​​e Launch 中单击按钮的标题的值?

问题描述

我想使用 Adob​​e Launch 中数据元素的自定义代码获取被点击元素的父元素的文本值。

我使用了 $('h2.cmp-teaser__title.wow.animated').text();方法

当我点击按钮时:("a.cmp-teaser__action-link") 它应该得到标题的值("cmp-teaser__title.wow.animated") 但是当我用调试工具检查时,文本值没有正确收集。 Adobe Launch 中数据元素的自定义代码

我的代码供参考:

<div class="cmp-teaser__content">
        <div class="cmp-teaser__pretitle">Feature Title</div>        
    <div class="cmp-teaser__title wow animated" style="visibility: visible;">
        <h2>broclux Title</h2>
    </div>
    <div class="cmp-teaser__description">
        <p>Sample text Sample text Sample text Sample text</p>
    </div>        
    <div class="cmp-teaser__action-container">        
    <a class="cmp-teaser__action-link" href="#.html" target="_self" title="">View Collection</a>
 </div>

解决方法

css 选择器不正确。 h2 在 div 内。

你会想要这个:

$('div.cmp-teaser__title.wow.animated > h2').text()
,

你需要使用这个。并且请避免使用 jquery。

您的数据元素应该只返回 this.parentElement.parentElement.querySelector("h2").innerText

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...