简体   繁体   English

C#Selenium Webdriver JavaScriptExecutor提示窗口

[英]C# Selenium Webdriver JavaScriptExecutor Prompt Window

I have a JavaScript Prompt Window which I am trying to handle. 我有一个要处理的JavaScript提示窗口。 I had one previously that was simply contained an 'OK' and 'Cancel' which I was able to handle with 我以前有一个简单地包含一个“ OK”和“ Cancel”,我可以使用

((IJavaScriptExecutor)ts.getDriver()).ExecuteScript("window.confirm = function(){return true; }")

However now I have another prompt message but this time it requires me to send text to the prompt message and then hit 'OK'. 但是,现在我又收到一条提示消息,但这一次它要求我将文本发送到提示消息,然后单击“确定”。 I am not real familiar with javascript and the syntax can anyone supply the syntax to hand sending the text to the prompt box? 我不是真的很熟悉javascript,有人可以提供语法来手动将文本发送到提示框吗?

UPDATE: The application I am trying to automate has generated a Windows Prompt. 更新:我正在尝试自动化的应用程序已生成Windows提示符。 In the past I have handled most of the alert pop ups with 过去,我已经处理了大多数警报弹出窗口

.SwitchTo().Alert().Accept();   

However this particular Windows Prompt (Please see image example) 但是,此特定的Windows提示符(请参见图片示例)

在此处输入图片说明

cannot be captured this way hence my use of JavaScript to handle the window Pop Up. 无法以这种方式捕获,因此我使用JavaScript来处理弹出窗口。 The reason I referenced the first section of code at the top was because this particular piece of code I used to handle the first Window Prompt. 我在顶部引用第一部分代码的原因是因为我用来处理第一个“窗口提示”的这段特殊代码。 The difference being this time the Windows Prompt Box has an 'OK' Button, a 'Cancel' Button AND a text box in it which I must enter some sort of text to close the prompt box. 这次的区别是Windows提示框上有一个“确定”按钮,一个“取消”按钮和一个文本框,我必须输入某种文本来关闭提示框。 All I am trying to find out is what syntax am I using to handle sending text into this Windows prompt for example: 我要查找的全部内容是用于处理向此Windows提示符发送文本的语法,例如:

((IJavaScriptExecutor)ts.getDriver()).ExecuteScript("window.confirm = function(){return true; }");

was used to close out the 'OK' prompt message but for a prompt box with text what should I be writing inside of the ExecuteScript 用于关闭“确定”提示消息,但对于带有文本的提示框,我应该在ExecuteScript中编写什么内容

((IJavaScriptExecutor)ts.getDriver()).ExecuteScript("???");

So basically what script should I be writing where the question marks are. 所以基本上我应该在问号所在的位置写什么脚本。

So this must be a pretty common use case for Selenium; 因此,对于Selenium来说,这一定是一个非常普遍的用例。 my experience is limited. 我的经验有限。 Googling around, however, I found the following: 但是,我在Google上搜索了以下内容:

Alert alert = driver.SwitchTo().Alert();
driver.SwitchTo().Alert().SendKeys("Hello");
alert.Accept();

(From SeleniumEasy ) (来自SeleniumEasy

I fixed the camel case for the C# implementation; 我修复了C#实现的驼峰式案例; the original example is in Java. 原始示例是在Java中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM