Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Testing 点击图片使用柏树_Testing_Cypress - Fatal编程技术网

Testing 点击图片使用柏树

Testing 点击图片使用柏树,testing,cypress,Testing,Cypress,如何使用Cypress单击收藏夹按钮?我试过: cy.contains('img',{matchCase:false})。单击({force:true}); cy.get('[alt=“Image”]')。单击(); cy.get('[src=“Images/outline_star_border_black_18dp.png”]')。单击({force:true}); 嗯,像这样的东西会有帮助。首先通过cy.xpath()或cy.get()查找元素,然后过滤更像具有src标记的元素,然后如果s

如何使用Cypress单击收藏夹按钮?我试过:

cy.contains('img',{matchCase:false})。单击({force:true});
cy.get('[alt=“Image”]')。单击();
cy.get('[src=“Images/outline_star_border_black_18dp.png”]')。单击({force:true});

嗯,像这样的东西会有帮助。首先通过cy.xpath()或cy.get()查找元素,然后过滤更像具有src标记的元素,然后如果src具有包含边框的url,则单击元素simple:)


我会通过获取工具栏并钻取它来接近它

cy.get('.topbar')  // get the containing toolbar
  .children()      // all the children with it
  .eq(1)           // take the second one
  .find('img')     // all the icons
  .eq(0)           // take the first one (NOTE they are reverse order to display)
  .click()
或者使用
.find()
和部分匹配源字符串以在工具栏中搜索

cy.get('.topbar')  // get the containing toolbar
  .find('img[src*="outline_star"]')     // *= gives a partial match on src
  .click()

const elem=cy.get('div[class=“col-lg-2 col-md-2”]”)。如果(elem.should('contain','outline\u star\u border\u black'){elem.click()}不起作用,则应('alt=“Image”,Images/outline\u star\u border\u black\u 18dp.png'))!我做错了吗?我们不能像您那样在.should()中使用我们选择的参数。读这篇文章写这个常量elem=cy.get('div[class=“col-lg-2 col-md-2”]>img')。如果你想在“alt”属性上断言,应该('have.attr','alt')。如果你想在“alt”属性上断言,写这个常量elem=cy.get('div[class=“col-lg-2 col-md-2”]>img')。如果你想在“alt”属性上断言,应该('have.attr','alt')属性,但问题是alt='image在div标记下不止一个,并且类名看起来也不是很唯一。尝试以下操作:cy.get('.topbar').children().eq(1).查找('img').eq(0).单击()
cy.get('.topbar')  // get the containing toolbar
  .find('img[src*="outline_star"]')     // *= gives a partial match on src
  .click()