3 回答

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊
無(wú)法弄清楚為什么我不能將這些相同類型的元素添加到我的列表中 -
您的代碼中很可能有拼寫錯(cuò)誤。它應(yīng)該是element而不是elements:
for (WebElement element : elements){
webElementList.add(element);
}
在“visibleWebElement”上出現(xiàn)此錯(cuò)誤 -
driver.findElement()方法接受一個(gè)By對(duì)象作為參數(shù),它是一個(gè)選擇器。但是您正在傳遞visibleWebElementswhich 是一個(gè)WebElement對(duì)象,這就是您的代碼出錯(cuò)的原因。例如,如果您想通過(guò) xpath 定位元素,這是使用它的正確方法:
WebElement your_element = driver.findElement(By.xpath("//whatever xpath"));
您可以直接isDisplayed()在 WebElement 上使用該方法:
public void estaVisible(WebElement visibleWebElements) {
boolean esvisible = visibleWebElements.isDisplayed();
Assert.assertTrue(esvisible);
return esvisible;
}

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊
此函數(shù)將返回一個(gè)布爾值并檢查列表元素是否可見(jiàn)。
public boolean isListElementsVisible(WebDriver driver, By locator) {
boolean result = false;
try {
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(locator));
result = true;
} catch (Exception e) {
System.out.println(e.getMessage());
result = false;
}
return result;
}
添加回答
舉報(bào)