我有元素 <%
String brands="";
String userBrands[];
String brandslist[]= {"bat", "cat", "ant", "batting", "antenna"};
if(user.get("brand")!=null && !user.get("brand").isEmpty()){
brands = user.get("brand").toLowerCase();
System.out.println("BRANDS: " + brands);
userBrands = brands.split(",");
}
//out.println(Arrays.toString(userBrands));
// to check if value there or not
boolean found;
for(int i= 0 ;i<brandslist.length ;i++){
found = false;
for(int j= 0 ;j<userBrands.length ;j++){
if(userBrands[j].equals(brandslist[i].toLowerCase().trim())){ %>
<option selected='selected' value='<%=brandslist[i].toLowerCase().trim()%>'><%=brandslist[i].trim()%></option>
<%
//value there
found = true;
}
}
//value not there found will remain false and below code will get executed
if(!found){ %>
<option value='<%=brandslist[i].trim().toLowerCase()%>'><%=brandslist[i].trim()%></option>
<%}
}%>
,具有以下属性newdevice
。
remove device from account
是唯一的,但是有很多相同的属性。
我无法执行点击按钮的问题。
newdevice
所以我希望找到新的元素,如果元素存在,则在下面的属性下找到属性并单击它。
答案 0 :(得分:0)
要在元素{strong> newdevice 中的文本为从帐户中删除设备的元素上click()
,您必须诱使 WebDriverWait elementToBeClickable()
,则可以使用以下Locator Strategies中的任何一个:
xpath 1 :
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//td/strong[text()='newdevice']//following::td[3]//button[contains(@title, 'remove device')]"))).click();
xpath 2 :
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//td/strong[text()='newdevice']//following::td//button[@title='remove device from account']"))).click();