【发布时间】:2020-07-10 12:17:46
【问题描述】:
步骤:
- 导航到https://qaclickacademy.github.io/protocommerce/shop
- 点击店铺
- 选择一些移动品牌并加入购物车
- 点击结帐按钮
- 提取每个手机的总值并打印
问题:我正在使用下面的定位器点击添加按钮 [ element.all(by.css("button[class*='btn-info']")).click() ]
但似乎所有的添加按钮都有相同的代码。 默认情况下,第一个“添加”按钮被多次单击,并且重复添加相同的移动设备。
谁能帮我解决这个问题?
我的量角器代码:
describe('Assignment',function(){
function Shopping(MobileBrand){
//Use tag name locator when only tag name is present
element.all(by.tagName("app-card")).each(function(value){
//when single h4 and single a tag use them directly no need to give attribute='value'
value.element(by.css("h4 a")).getText().then(function(name){
if(name==MobileBrand)
{
console.log("Mobile Name Retrieved" +name);
console.log("Mobile Name Provided" +MobileBrand);
//Click on Add button
element.all(by.css("button[class*='btn-info']")).click().then(function(){
browser.sleep(5000);
});
}
})
})
}
it('Task',function(){
browser.driver.manage().window().maximize();
browser.get("https://qaclickacademy.github.io/protocommerce/");
element(by.linkText("Shop")).click();
//Pass the mobile brands to be selected
Shopping("Samsung Note 8");
Shopping("Nokia Edge");
Shopping("Blackberry");
element(by.partialLinkText("Checkout")).click().then(function(){
browser.sleep(5000);
})
});
})
【问题讨论】:
标签: javascript protractor