在下面的代碼中,雖然我已經聲明和初始化selenium webdriver中的警報,但在selenium webdriver中會出現以下錯誤。當在selenium webdriver中聲明和啓動警報類型不匹配:無法從警報轉換爲警報錯誤即將到來
Alert action = wait.until(ExpectedConditions.alertIsPresent());
在上述警報
類型不匹配:不能從警報轉換通知
快到了,雖然上述警報正確聲明。
在下面的代碼中,雖然我已經聲明和初始化selenium webdriver中的警報,但在selenium webdriver中會出現以下錯誤。當在selenium webdriver中聲明和啓動警報類型不匹配:無法從警報轉換爲警報錯誤即將到來
Alert action = wait.until(ExpectedConditions.alertIsPresent());
在上述警報
類型不匹配:不能從警報轉換通知
快到了,雖然上述警報正確聲明。
這裏是回答你的問題:
根據你的問題,你所提供的代碼下面一行:
Alert action = wait.until(ExpectedConditions.alertIsPresent());
語法上你是非常正確的。
觀察下面的代碼塊快照,alertIsPresent()
的調用返回ExpectedCondition<Alert>
,我們必須將它分配給Alert
類的對象,這是通過您的代碼完成的。
現在來到誤差部分,你看到Type mismatch: cannot convert from Alert to Alert
最可能的原因可能是你的代碼不完整或丟失的進口。要使這行代碼正常工作,您必須具備以下條件:
WebDriverWait
的實例。imports
一個例子:
import org.openqa.selenium.Alert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
//your code
WebDriverWait wait8 = new WebDriverWait(driver, 10);
Alert action = wait8.until(ExpectedConditions.alertIsPresent());
通過這個你應該看到過的錯誤。
讓我知道這個答案是否是您的問題。
第一行應該是wait.until(ExpectedConditions.alertIsPresent());緊接着是Alert action = driver.switchToalert(); –
你使用了什麼導入'Alert'? – Guy
可以添加完整的異常堆棧跟蹤嗎? – Murthi