【发布时间】:2018-08-05 10:03:17
【问题描述】:
谁能给出这个 div 元素的更好的 xpath,或者帮助解释为什么我似乎无法选择所需的 div?
此 XPath 不起作用:
//div[starts-with(normalize-space(.),'Welcome to the Shipt Shopper') and @class='text']
即使它在 chrome 开发工具中突出显示,也会抛出 NoSuchElementException。
页面上的所有元素都是这种情况
来自页面的 HTML 的 sn-p,其中包含我要定位的内容:
<div class="content-wrapper">
<div class="content" style="padding-top: 116px;">
<div class="media">
<div class="attachment" data-attachment="{"image":"https:\/\/images.typeform.com\/images\/29rsVwT3VF\/image\/default#.png","width":360,"height":137,"video_source":"","video_id":""}" style="width: 360px; height: 137px;">
<img src="https://images.typeform.com/images/29rsVwT3VF/image/default#.png" data-original="https://images.typeform.com/images/29rsVwT3VF/image/default#.png" style="width: 360px; height: 137px; display: inline;">
</div>
</div>
<div class="text" style="padding-top: 30px; margin-left: 0px;">
Welcome to the Shipt Shopper application! <br><br>Ready to get started?
</div>
<div class="button-wrapper" style="margin-top: 30px;">
<div class="button general full enabled hover-effect" style="">Begin</div>
<div class="button-text">press <strong>ENTER</strong></div>
</div>
</div>
</div>
【问题讨论】:
-
元素是动态注入的吗?
-
图片中的html
-
...是的,我问的是 HTML 的那部分是否通过一些外部事件(例如按钮单击或弹出)注入到 DOM 中。
-
如果您发布 HTML 的 sn-p 会有所帮助,而不仅仅是开发人员工具的屏幕截图。例如,我们可以更容易地确定引号是否是文本的一部分。
-
@SharonJones 您需要等待 iframe 完成加载。使用将自动切换到 iframe 的 frameToBeAvailableAndSwitchToIt(String frameLocator) 预期条件。然后使用查询查找欢迎文本。 seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/…
标签: selenium xpath selenium-webdriver