如何在Laravel黄昏中处理同一个类的多个元素 [英] How to handle multiple elements with the same class in laravel dusk
问题描述
在我的黄昏测试中,我想先添加然后删除新闻.每个新闻都有 .delete-news 类,但是在屏幕上我有多个元素.每个.delete-news类的id为 data-newsid ="id" 的path数据属性.现在,浏览器不知道应该单击哪个delete-news类.我该如何处理?
In my dusk test I want to firstly add and then delete news. Each news has .delete-news class but on the screen I have multiple elements. Each .delete-news class has in it's path data attribute with it's id data-newsid="id". Now the browser does not know which delete-news class it should to click. How should I manage that?
可能我应该选择具有最大data-newsid属性的delete-news类.但是我不知道该怎么检查.
Probably I should take delete-news class with the biggest data-newsid attribute. But I don't know how I should check it.
目前,我正在像这样删除它:
Currently I'm deleting it like this:
public function testRemoveNews() {
$this->browse(function ($browser) {
$browser->visit('/')
->press('.delete_news')
->press('Yes')
->waitForText('News has been deleted!')
->press('OK')
->assertDontSee('Title of the news');
});
}
推荐答案
如果您按'id'desc
排序新闻,也许您应该尝试
If you sorting your news by 'id' desc
, maybe you should try
->press('.delete-news:first') // or :nth-child(1)
或向第一个新闻元素(例如 dusk ="last-news"
)添加 dusk
属性,并使用以下命令进行调用:
or add a dusk
attribute to first news element, like dusk="last-news"
, and call it with:
->press('@last-news')
这篇关于如何在Laravel黄昏中处理同一个类的多个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!