1
我在頁面上有一個按鈕,有時不會顯示。我想讓我的代碼繞過它,但它不適用於driver.findElement.isDisplayed()
。我正在考慮ExpectedConditions.elementToBeClickable
,但我不知道如何使它成爲布爾值。有些幫助嗎?(當然,條件是返回錯誤,因爲它不是布爾值)。我如何寫一個if語句來使按鈕可見?
WebDriverWait wait = new WebDriverWait(driver, 10);
if(ExpectedConditions.elementToBeClickable(By.xpath("html//body//div[5]//div//div//form//div//div[1]//div[3]//div//div//div//input")).){
WebElement ex = driver.findElement(By.xpath("//*[@class='ng-pristine ng-untouched ng-valid'][@value='export'][@type='radio']"));
ex.click();
WebElement in = driver.findElement(By.xpath("html//body//div[5]//div//div//form//div//div[1]//div[3]//div//div//div//input"));
in.click();
}else{new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("html//body//div[5]//div//div//form//div//div[1]//div[3]//div//div//div//input")));}
'
您可以總是轉換語句,拋出一個異常,而不是返回false到布爾語句與try/catch塊。 –