如何從WebElement
獲取Findby
類型和字符串?如何從WebElement獲取Findby類型和字符串
我正在使用自建的webDriverWait
函數,該函數將能夠接收By或Webelement以用於presenceOfElementLocated()函數。
定義WebElement
@FindBy(xpath = "//div[@id='calendar-1234']")
private WebElement calander;
的兩個webDriverWaitFor功能
第一個使用由和工作沒關係:,第二個使用webElement
public void webDriverWaitFor(WebDriver driver, By by) throws ElementLocatorException {
try{
(new WebDriverWait(driver, 5))
.until(ExpectedConditions.presenceOfElementLocated(by));
}
catch (Exception e) {
throw new ElementLocatorException(by);
}
}
第二個使用WebElement我正在嘗試獲取By類型和字符串。 這implimintation不好:By.id(webElement.getAttribute( 「ID」))
public void webDriverWaitFor(WebDriver driver, WebElement webElement) throws ElementLocatorException {
try{
(new WebDriverWait(driver, 5))
.until(ExpectedConditions.presenceOfElementLocated( By.id(webElement.getAttribute("id"))));
}
catch (Exception e) {
throw new ElementLocatorException(By.id(webElement.getAttribute("id")));
}
}
我如何能夠實現以下?
webDriverWaitFor(driver, calander);
如何使用pagefactory編寫自定義'isElementPresent'。如果沒有pagefactory它是這樣寫的: '嘗試{ \t \t \t如果(driver.findElements(定位).size()> 0){ \t \t \t \t迴歸真實; \t \t \t} else \t \t \t \t return false; \t \t} \t \t趕上(例外五){ \t \t \t返回假; \t \t}' – paul