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
Testing 如何以编程方式按下“警报确定”按钮?_Testing_Selenium_Selenium Rc_Alert - Fatal编程技术网

Testing 如何以编程方式按下“警报确定”按钮?

Testing 如何以编程方式按下“警报确定”按钮?,testing,selenium,selenium-rc,alert,Testing,Selenium,Selenium Rc,Alert,如何以编程方式按下JS警报中的OK按钮 我想做的是:每次创建警报后,都会按下OK按钮 这是用于使用Selenium RC的UI测试 另外,我已经检查了: 编辑:我已经使用了选择okonnextconfirmation()。我还试着把它放在后面。什么都没用 你不能。除非您使用可以控制浏览器的东西(例如selenium) 如果您确实使用硒,请查看您不能使用的硒。除非您使用可以控制浏览器的东西(例如selenium) 如果您确实使用了selenium,请查看如果您可以模拟空格键或enter键的按键,则

如何以编程方式按下JS警报中的OK按钮

我想做的是:每次创建警报后,都会按下OK按钮

这是用于使用Selenium RC的UI测试

另外,我已经检查了:


编辑:我已经使用了
选择okonnextconfirmation()。我还试着把它放在后面。什么都没用

你不能。除非您使用可以控制浏览器的东西(例如selenium)


如果您确实使用硒,请查看您不能使用的硒。除非您使用可以控制浏览器的东西(例如selenium)


如果您确实使用了selenium,请查看

如果您可以模拟空格键或enter键的按键,则会解除警报。然而,你最好从外部做这件事,无论什么让警报在第一时间出现,因为它们往往是阻塞的


如果这是JavaScript,您最好使用
console.log()

如果您可以模拟空格键或enter键,则会解除警报。然而,你最好从外部做这件事,无论什么让警报在第一时间出现,因为它们往往是阻塞的


如果这是JavaScript,那么最好使用
console.log()

如果可以看到警报对话框,则无法执行。Selenium应该为您处理。但是:

Selenium试图对您隐藏这些对话框(通过替换 window.alert、window.confirm和window.prompt)这样他们就不会停止 执行您的页面。如果您看到一个警告弹出窗口,它是 可能是因为它在页面加载过程中触发,这是 对于我们来说,保护页面通常为时过早

这是Selenium RC(因此也是Selenium IDE)的一个已知限制,也是Selenium 2(WebDriver)开发的原因之一。如果您想捕获
onload
JS警报,您需要

也就是说,您可以使用或填写任何文本,然后按Enter键并盲目确认对话框。这不是最干净的方法,但它可以工作。但是,您将无法获取
警报
消息


Robot
将所有有用的键映射到常量,这样做很容易。使用
keyPressNative()
,您希望使用
10
作为按Enter键的值,或者使用
27
作为按Esc键的值,因为它可以与一起工作。

如果您确实可以看到警报对话框,则无法执行此操作。Selenium应该为您处理。但是:

Selenium试图对您隐藏这些对话框(通过替换 window.alert、window.confirm和window.prompt)这样他们就不会停止 执行您的页面。如果您看到一个警告弹出窗口,它是 可能是因为它在页面加载过程中触发,这是 对于我们来说,保护页面通常为时过早

这是Selenium RC(因此也是Selenium IDE)的一个已知限制,也是Selenium 2(WebDriver)开发的原因之一。如果您想捕获
onload
JS警报,您需要

也就是说,您可以使用或填写任何文本,然后按Enter键并盲目确认对话框。这不是最干净的方法,但它可以工作。但是,您将无法获取
警报
消息


Robot
将所有有用的键映射到常量,这样做很容易。使用
keyPressNative()
,您希望使用
10
作为按Enter键的值,或者使用
27
作为按Esc键的值,因为它可以与一起工作。

使用chooseOkOnNextConfirmation可以这样做

selenium.chooseOkOnNextConfirmation();  // prepares Selenium to handle next alert
selenium.click(locator);
String alertText = selenium.getAlert(); // verifies that alert was shown
assertEquals("This is a popup window", alertText);

有关详细信息,请通过此链接,选择OK ONNEXT确认您可以执行此操作

selenium.chooseOkOnNextConfirmation();  // prepares Selenium to handle next alert
selenium.click(locator);
String alertText = selenium.getAlert(); // verifies that alert was shown
assertEquals("This is a popup window", alertText);

有关更多信息,请访问此链接。

您可以使用GSEvent.h处理任何类型的按键事件,它在GraphicsServices框架中可用,它是私有framewrk(因此,您无法在appstore上提交)。

您可以使用GSEvent.h处理任何类型的按键事件,它在GraphicsServices框架中可用,它是私有framewrk(因此,您无法在appstore上提交它)。

selenium.chooseOkOnNextConfirmation();在Selenium RC为我工作


我们必须对Alert OK按钮的代码进行注释,然后它才能工作。

selenium.chooseOkOnNextConfirmation();在Selenium RC为我工作

$this->chooseOkOnNextConfirmation();
$this->click('locator');
$this->getConfirmation();
我们必须对Alert OK按钮的代码进行注释,然后它才能工作

$this->chooseOkOnNextConfirmation();
$this->click('locator');
$this->getConfirmation();
使用Selenium RC和PHPUnit,上述过程对我有效

使用Selenium RC和PHPUnit,上述过程对我有效

您想在“显示警报”、“确定”和“取消”按钮中尝试此代码

let sharephotoAction = UIAlertController.init(title: "Confirm Ticket", message:"Please Collect Your Ticket Before 1 Hours Ago in Location", preferredStyle: .alert )
        sharephotoAction.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (alertAction) in

            _ = Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(self.Save), userInfo: nil, repeats: false)

        }))
        sharephotoAction.addAction(UIAlertAction(title: "Cancle", style: .default, handler:nil))

        self.present(sharephotoAction, animated: true, completion:nil)
斯威夫特3

您想在“显示警报”、“确定”和“取消”按钮中尝试此代码

let sharephotoAction = UIAlertController.init(title: "Confirm Ticket", message:"Please Collect Your Ticket Before 1 Hours Ago in Location", preferredStyle: .alert )
        sharephotoAction.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (alertAction) in

            _ = Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(self.Save), userInfo: nil, repeats: false)

        }))
        sharephotoAction.addAction(UIAlertAction(title: "Cancle", style: .default, handler:nil))

        self.present(sharephotoAction, animated: true, completion:nil)

我做了很多事情,看了看那个问题,但什么都没用。无论如何谢谢你!我做了很多事情,看了看那个问题,但什么都没用。无论如何谢谢你!您仍然使用Selenium RC有什么原因吗?它已被正式弃用。您可以使用
chooseOkOnNextConfirmation
进行此操作。您是否仍在使用Selenium RC?它已被正式弃用。您可以使用
选择OkonnextConfirmation
进行此操作。