为什么我的 Selenium 网络驱动程序没有点击由 id 标识的元素?
Why my Selenium web driver is not clicking on Element identified by id?
我的 Selenium Web 驱动程序没有点击这个树节点。我不确切知道我们所说的树节点或其他东西,所以这是图像,我突出显示了该元素。
我要点击的右箭头部分
这是我的代码:
//wait.until(ExpectedConditions.elementToBeClickable(By.id("iconDiv")));
WebElement taskdropElementid = driver.findElement(By.id("iconDiv"));
System.out.println(taskdropElementid.getAttribute("class"));
if(taskdropElementid.getAttribute("class").equals("RightArrow"))
taskdropElementid.click();
打印语句为我提供了输出下拉列表。我认为它应该给 RightArrow,当我取消注释等待部分时,它会不断等待元素可点击。
我做错了什么?
Printing statement is giving me output dropdown
这意味着有多个具有相同 ID iconDiv
的元素,不幸的是,您正在定位其他具有 class 名称 dropdown
.
的元素
如果您想定位名称为 class 的元素 RightArrow
,您应该尝试使用 By.cssSelector()
来唯一定位它,如下所示:-
WebElement taskdropElementid = driver.findElement(By.cssSelector("div#iconDiv.RightArrow"));
taskdropElementid.click();
我的 Selenium Web 驱动程序没有点击这个树节点。我不确切知道我们所说的树节点或其他东西,所以这是图像,我突出显示了该元素。
我要点击的右箭头部分
这是我的代码:
//wait.until(ExpectedConditions.elementToBeClickable(By.id("iconDiv")));
WebElement taskdropElementid = driver.findElement(By.id("iconDiv"));
System.out.println(taskdropElementid.getAttribute("class"));
if(taskdropElementid.getAttribute("class").equals("RightArrow"))
taskdropElementid.click();
打印语句为我提供了输出下拉列表。我认为它应该给 RightArrow,当我取消注释等待部分时,它会不断等待元素可点击。
我做错了什么?
Printing statement is giving me output dropdown
这意味着有多个具有相同 ID iconDiv
的元素,不幸的是,您正在定位其他具有 class 名称 dropdown
.
如果您想定位名称为 class 的元素 RightArrow
,您应该尝试使用 By.cssSelector()
来唯一定位它,如下所示:-
WebElement taskdropElementid = driver.findElement(By.cssSelector("div#iconDiv.RightArrow"));
taskdropElementid.click();