gpt4 book ai didi

rspec - Capybara 期待 page.selector to_have

转载 作者:行者123 更新时间:2023-12-01 09:02:56 25 4
gpt4 key购买 nike

我需要验证页面特定部分中是否存在某些文本。
expect(page).to会输出太多的文字,尤其是带有协议(protocol)条款的页面,总是那么长。

我想改造expect(page).to(have_text(变成 expect('#id').to(have_text(...) 之类的东西

我不知道如何选择 ID 引用的页面部分。我应该写我的expect(page)within('#id') 内?

编辑:如果可能的话,一个针对嵌套标签的解决方案

<div id="id">
<span class="nested">...</span>
Text I want to check with have_text()
</div>`

最佳答案

您在这里有多种选择,要么

section = find(:css, '#id') #the :css may be optional depending on your Capybara.default_selector setting
# or - section = find_by_id('id')
expect(section).to have_text(...)

或者
expect(page).to have_css('#id', text: '...')

或者
expect(page).to have_selector(:id, 'id', text: '...')

取决于您是否需要该元素来做其他事情。

关于rspec - Capybara 期待 page.selector to_have,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38043555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com