我正在嘗試關閉使用java的selenium web驅動程序彈出。我嘗試了不同的方式,但無法成功。請幫幫我。如何關閉在硒webdriver彈出?
package Demo;
import java.util.Set;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class YahooTest {
public static void main(String[] args) throws InterruptedException {
FirefoxDriver obj = new FirefoxDriver();
String url = "https://www.planyourjourney.com/";
obj.get(url);
obj.manage().window().maximize();
obj.findElement(By.xpath("html/body/div[12]/div/div/div[9]")).click();
obj.findElementByClassName("dyna-link-new-registration").click();
obj.findElement(By.linkText("B2B Login")).click();
Thread.sleep(4000);
obj.findElement(By.id("userid")).clear();
obj.findElement(By.id("userid")).sendKeys("[email protected]");
obj.findElement(By.id("ulPassword")).clear();
obj.findElement(By.id("ulPassword")).sendKeys("spyj01");
obj.findElement(By.name("Next")).click();
Thread.sleep(2000);
obj.findElement(By.id("affilitetrainadvpage"));
Alert alert = obj.switchTo().alert();
alert.dismiss();
}
}
你究竟試過了什麼?提供您的Java代碼以及彈出的HTML代碼 – Andersson
http://sqa.stackexchange.com/questions/5310/how-to-close-pop-up-window-in-selenium-webdriver – fabersky
請格式化您的代碼。這是不可讀的。 – Tom