7

Alertにあるメッセージを読みたい。

例:アラートに「間違った電子メールアドレス」が表示された場合。読み方は?そのメッセージを文字列に保存したいという意味です。

アラート内で[OK]をクリックする方法...??

Seleniumを使用してそれを行う方法は?

4

2 に答える 2

12

SeleniumWebDriverを使用していると想定しています。

// Get a handle to the open alert, prompt or confirmation
Alert alert = driver.switchTo().alert();
// Get the text of the alert or prompt
alert.getText();  
// And acknowledge the alert (equivalent to clicking "OK")
alert.accept();

答えはここで見つかりました。

Selenium RCを使用している場合は、このWebページを参照してください。

于 2012-05-17T10:27:34.270 に答える
0

Selenium RCでは、確認ボタンがあることがわかっている場合は、コードに追加する必要があることがわかりました。selenium.getConfirmation();

これが私がそれをどのように使用したかです(:私はEclipseでJavaを使用しています)

selenium.click("//input[@id=\"accepted-emails\"]"); // Confirmation box after this line
if (selenium.isConfirmationPresent())
    String confirmationString = selenium.getConfirmation(); // this line is needed
selenium.keyPressNative("10"); // to press the OK key
selenium.waitForPageToLoad("30000");
System.out.println(confirmationString); // this is not really needed, but used it to simply show the confirmation box message

お役に立てれば!

于 2012-08-08T09:33:42.370 に答える