Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium 如何单击&x201C;好的”;在弹出窗口中“;来自网页的消息”;在硒c#中?_Selenium_Automation_Selenium Webdriver - Fatal编程技术网

Selenium 如何单击&x201C;好的”;在弹出窗口中“;来自网页的消息”;在硒c#中?

Selenium 如何单击&x201C;好的”;在弹出窗口中“;来自网页的消息”;在硒c#中?,selenium,automation,selenium-webdriver,Selenium,Automation,Selenium Webdriver,我有一个应用程序,在点击按钮后,会弹出一个标题为MessagefromWebpage的弹出窗口,显示错误消息。我想点击上面的Ok按钮并验证错误消息。 我尝试了以下代码 public void clickButtonWithOk() { try { Thread.Sleep(Convert.ToInt32(GlobalVariables.WaitTime.ToString()) * 1000); // Get

我有一个应用程序,在点击按钮后,会弹出一个标题为MessagefromWebpage的弹出窗口,显示错误消息。我想点击上面的Ok按钮并验证错误消息。 我尝试了以下代码

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

它怎么会不起作用?它不会点击弹出窗口上的“确定”按钮。这里有很多未知数。
getApplicationObject
做什么?它的回报是什么?所有这些javascript都是为了什么?这是JavaScript警报吗?如果是这样的话,为什么不使用内置的Selenium方法呢?事实上,我使用的是一个框架,其中有一个对象存储库excel,其中有对象名称、类型(xpath/id/linktext等)和唯一id。还有一个excel,其中包含的关键字就是上面的函数(clickButtonWithOk)等等,函数将在其上工作的对象名称(从对象存储库提取)和输入数据(如果需要)。因此,getApplicationObject将从对象存储库(对于用关键字指定的对象名)中提供当前对象名、类型及其唯一id。此函数的作用是单击一个按钮,然后弹出一个弹出窗口。我想在该弹出窗口上单击“确定”。