【发布时间】:2021-10-20 01:40:32
【问题描述】:
我正在尝试检索 HTML 中 <style> 标记中定义的值,但不断收到无法找到该元素的错误
//div[contains(@class,'StageModuleText')]//style
从 RobotFramework 得到这个错误
Element '//div[contains(@class,'StageModuleText')]//style' not visible after 30 seconds
这是 HTML
<style>
.item_5b8bfb83-375e-4605-8388-01340ea4bc61_7642733d-4309-4e81-8f64-5a6a55f4994a_d21bf969-efd0-46eb-9545-4cbbd550139e a {
color: #bc206e
}
</style>
我正在尝试获取颜色的值,但我什至找不到元素。但是当控制台打开时,我可以使用 xpath 在元素选项卡中轻松找到它
编辑: 这是一个更广泛的代码示例:
<div class="editor-outer StageModuleText_wrapper__3kHNI item_60036ccd-a7a8-41f3-b858-d0db08f31cfa_06fab0b6-0ab8-4000-a162-7d1dc8bf97c2_b5ce6362-949f-4b81-bf9c-9a0ebc46bc63">
<style>
.item_60036ccd-a7a8-41f3-b858-d0db08f31cfa_06fab0b6-0ab8-4000-a162-7d1dc8bf97c2_b5ce6362-949f-4b81-bf9c-9a0ebc46bc63 a {
color: #44a1a9
}
.editor_item_60036ccd-a7a8-41f3-b858-d0db08f31cfa_06fab0b6-0ab8-4000-a162-7d1dc8bf97c2_b5ce6362-949f-4b81-bf9c-9a0ebc46bc63 * {
line-height: 1.2 !important;
}
</style>
<div class="editor-wrapper editorwrapper_text editor_item_60036ccd-a7a8-41f3-b858-d0db08f31cfa_06fab0b6-0ab8-4000-a162-7d1dc8bf97c2_b5ce6362-949f-4b81-bf9c-9a0ebc46bc63 StageModuleText_editorWrapper__19Z6l">
<div id="mce_66c9e9a4_8d68-41e5-b662-d7be6a68391c" tabindex="-1" class="mce-content-body" contenteditable="true" style="position: relative;">
<div class="txtTinyMce-wrapper" style="font-size: 14px; line-height: 28px;" data-mce-style="font-size: 14px; line-height: 28px;">
<p style="font-size: 14px;" data-mce-style="font-size: 14px;">I'm a new Text block ready for your content.</p>
</div>
</div>
</div>
</div>
【问题讨论】:
-
not visible after 30 seconds并不表示“元素无法找到”,而是表示它不可见。请注意,style节点在任何情况下都不会可见 -
你能分享相关的HTML或页面URL吗?
-
为什么不直接使用 By.tagName("style")
-
@Kundan : 因为 HTML 中可能有多个样式标签,而 OP 肯定不想要第一个样式标签。
-
@cruisepandey 我的意思是将 div 元素存储在一个变量中,然后在该变量上使用 findElement(By.tagName()) 。抱歉,我的第一条评论不清楚。或者,你不能只获取 div 标签的文本并从中提取颜色值吗?
标签: css selenium xpath automation robotframework