页面对象模型错误,属性值必须恒定

时间:2019-10-21 04:08:39

标签: java appium

我想获取元素,但其元素用于日历和与数字相关的ID,我想从1到28随机数: 示例元素:

calendarCell1

calendarCell2

所以这是我的代码

public static final Random rand = new Random();
public static final Integer min =1;
public static final Integer max =28;
public static final Integer value = rand.nextInt((max-min)+1)+min;
public static final String number = Integer.toString(value);
public static final String calendar = “calendarCell”+number+;

@iOSFindBy (xpath = " //*[contains(text()='"+calendar+"']")
IOSElement randomCalendar;

但是我遇到错误iosfindby行中属性值必须恒定 有什么建议吗?

1 个答案:

答案 0 :(得分:0)

看看是否可行-

public static final Random rand = new Random();
public static final Integer min =1;
public static final Integer max =28;
public static final Integer value = rand.nextInt((max-min)+1)+min;
public static final String number = Integer.toString(value);
public static final String calendar = “calendarCell”+number+;
public static final String XPATH = " //*[contains(text()='"+calendar+"']";

@iOSFindBy (xpath = XPATH)
IOSElement randomCalendar;