Alertにあるメッセージを読みたい。
例:アラートに「間違った電子メールアドレス」が表示された場合。読み方は?そのメッセージを文字列に保存したいという意味です。
アラート内で[OK]をクリックする方法...??
Seleniumを使用してそれを行う方法は?
Alertにあるメッセージを読みたい。
例:アラートに「間違った電子メールアドレス」が表示された場合。読み方は?そのメッセージを文字列に保存したいという意味です。
アラート内で[OK]をクリックする方法...??
Seleniumを使用してそれを行う方法は?
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ページを参照してください。
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
お役に立てれば!