Java 如果元素是动态的,则无法定位元素
我收到错误消息,无法定位元素,即使它是从DD中选择的 我的元素是动态的 我试过这种方法Java 如果元素是动态的,则无法定位元素,java,selenium,xpath,css-selectors,webdriverwait,Java,Selenium,Xpath,Css Selectors,Webdriverwait,我收到错误消息,无法定位元素,即使它是从DD中选择的 我的元素是动态的 我试过这种方法 static class GroupCount { private static int i = 1; static void inc() { i++; } static int g
static class GroupCount {
private static int i = 1;
static void inc() {
i++;
}
static int get() {
return i;
}
}
String xpathGroupSelect = "//*[@id='groupPicker" +
GroupCount.get() + "-list']//div[contains(concat(' ','x-combo-list-item', ' '), 'x-combo-list-item') " +
"and contains(text(),'"
+ name + "')]";
WebElement group = driver.findElement(By.xpath(xpathGroupSelect));
if (xpathGroupPick.isDisplayed()) {
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(group)).click();
group.click();
WorkflowAction.addApprovers("Compliance");
我试图找到“合规性”元素
以下是我的html代码:
> <div class="x-combo-list-inner" id="groupPicker1-list" style="width:
> 218px; margin-bottom: 8px; height: 81px;"> <div
> class="x-combo-list-item" style="">APPROVAL</div> <div
> class="x-combo-list-item" style="">Compliance</div> <div
>class=“x-combo-list-item”style=”“>批准class=“x-combo-list-item”style=”“>合规性要定位文本为合规性的元素,您需要为元素的可见性诱导WebDriverWait()
,您可以使用以下任一选项:
css选择器
:
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.x-combo-list-inner[id^='groupPicker'] div:nth-child(2)")));
xpath
:
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='x-combo-list-inner' and starts-with(@id, 'groupPicker')]//div[@class='x-combo-list-item' and text()='Compliance']")));
您要查找哪一个元素?我正在尝试确定“合规性”元素此处id是动态的,因此无法使用“gropupicker1”签出更新的答案并让我知道状态,现在它应该与gropupicker1、gropupicker2、gropupicker3等一起使用