editMethod(){
var num = Math.floor((Math.random() *4) + 1);
var xPath_arr= [
'//android.widget.RadioButton[@text="seat1"]',
'//android.widget.RadioButton[@text="seat2"]',
'//android.widget.RadioButton[@text="seat3"]',
'//android.widget.RadioButton[@text="Notselected"]',
]
xPath_arr[num]
}
Then calling in another function like this
selectseat(){
this.editmethod();
this.doneBtn.click();
}
尝试了不同的方法,但是收到了不同的错误,例如
但不起作用
TypeError:无法读取未定义的属性'2'
const editMethod = () => {
let num = Math.floor((Math.random() * 3) + 1);
console.log(num)
let xPath_arr = [
'//android.widget.RadioButton[@text="seat1"]',
'//android.widget.RadioButton[@text="seat2"]',
'//android.widget.RadioButton[@text="seat3"]',
'//android.widget.RadioButton[@text="Notselected"]',
]
return xPath_arr[num];
}
// Then calling in another function like this
const selectseat =() => {
let seatElement = editMethod();
console.log(locator);
}
selectseat();
注意:
Math.random()* 3应该是因为您的数组仅包含4个元素。