我有一个应用程序,在点击按钮后,一个名为“来自网页的消息”的弹出窗口显示错误消息。我想单击“确定”按钮并验证错误消息。 我尝试了以下代码
public void clickButtonWithOk()
{
try
{
Thread.Sleep(Convert.ToInt32(GlobalVariables.WaitTime.ToString()) * 1000);
// Get element at runtime
inputData = "45";
waitForElementDisplayed();
int runTimeObjectSize = driver.FindElements(getApplicationObject(currentObjectName, currentObjectType, currentObjectUniqueId)).Count;
if (runTimeObjectSize == 0)
STEPLogger.logmessage(STEPLogger.FAIL, "FAILED to click button " + currentObjectName + " Object NOT Found");
else
{
IWebElement element = driver.FindElements(getApplicationObject(currentObjectName, currentObjectType, currentObjectUniqueId))[0];
IJavaScriptExecutor executor = (IJavaScriptExecutor)driver;
executor.ExecuteScript("window.confirm = function(msg){return true;};");
executor.ExecuteScript("arguments[0].click();", element);
STEPLogger.logmessage(STEPLogger.PASS, "SUCCESSFULLY clicked on button " + currentObjectName);
}
}
catch (Exception oException)
{
STEPLogger.logmessage(STEPLogger.FAIL, "FAILED clickButton:" + oException.ToString());
}
} // End of CLICKBUTTONWithOk