私は開いたときにログインするためのユーザー名とパスワードを入力する必要がある警告ボックスを表示するWebサイトを持っています。どうやってやるの?javaを使用してセレンのアラートボックスにユーザー名とパスワードを入力する方法は?
this linkをクリックしてください。
私は開いたときにログインするためのユーザー名とパスワードを入力する必要がある警告ボックスを表示するWebサイトを持っています。どうやってやるの?javaを使用してセレンのアラートボックスにユーザー名とパスワードを入力する方法は?
this linkをクリックしてください。
Please check with this
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class JavaScriptAlertTest {
public static void main(String[] args) {
WebDriver myTestDriver = new FirefoxDriver();
myTestDriver.get("...blablabla....");
myTestDriver.manage().window().maximize();
myTestDriver.findElement(By.xpath("//input[@value = 'alert']")).click();
Alert javascriptAlert = myTestDriver.switchTo().alert();
System.out.println(javascriptAlert.getText()); // Get text on alert box
javascriptAlert.accept();
System.out.println("*************prompt******************************************");
myTestDriver.findElement(By.xpath("//input[@value = 'prompt']")).click();
Alert javascriptprompt = myTestDriver.switchTo().alert();
javascriptprompt.sendKeys("This is Selenium Training");
System.out.println(javascriptprompt.getText()); // Get text on alert box
javascriptprompt.accept();
javascriptprompt = myTestDriver.switchTo().alert();
System.out.println(javascriptprompt.getText()); // Get text on alert box
javascriptprompt.accept();
myTestDriver.findElement(By.xpath("//input[@value = 'prompt']")).click();
javascriptprompt = myTestDriver.switchTo().alert();
System.out.println(javascriptprompt.getText()); // Get text on alert box
javascriptprompt.dismiss();
javascriptprompt = myTestDriver.switchTo().alert();
System.out.println(javascriptprompt.getText()); // Get text on alert box
javascriptprompt.accept();
System.out.println("***********************************confirm dialog box****************************");
myTestDriver.findElement(By.xpath("//input[@value = 'confirm']")).click();
Alert javascriptconfirm = myTestDriver.switchTo().alert();
javascriptconfirm.accept();
javascriptconfirm = myTestDriver.switchTo().alert();
System.out.println(javascriptconfirm.getText()); // Get text on alert box
javascriptconfirm.accept();
myTestDriver.findElement(By.xpath("//input[@value = 'confirm']")).click();
javascriptconfirm = myTestDriver.switchTo().alert();
javascriptconfirm.dismiss();
javascriptconfirm = myTestDriver.switchTo().alert();
System.out.println(javascriptconfirm.getText()); // Get text on alert box
javascriptconfirm.accept();
}
}
Ref:https://www.seleniumeasy.com/selenium-tutorials/how-to-handle-javascript-alerts-confirmation-prompts
http://stackoverflow.com/questions/8244723/alert-handling-in-selenium-webdriver-selenium-2-with-java
テキストを渡す場合は、sendKeysメソッドを使用することもできます – Pradeep
スイッチフレームの概念を使用できます。
このコードを使用して、子ウィンドウに切り替えてから親ウィンドウに戻すことができます。
コード:私はこれがあなたの問題
を解決することを願っています
は、この使用してHTTP基本ですか?その場合は、URLに資格情報を渡します。 – chrylis
http://stackoverflow.com/questions/11522434/how-to-handle-login-pop-up-window-using-selenium-webdriver – Gelbi