我试图学习 selenium ,我用flipkart网站自动化,但当我重定向到flipkart我无法关闭弹出窗口
我通过xpath和classname使用了“x”按钮,但它不起作用[img] https://i.ibb.co/7bhDJYw/Screenshot-2022-11-29-at-10-31-19-AM.png[/img]
package ui;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Popup {
public static String browser = "Firefox";
public static FirefoxDriver driver;
public static void main(String args[]) throws InterruptedException {
if (browser.equals("Firefox")) {
WebDriverManager.firefoxdriver().setup();
driver = new FirefoxDriver();
} else if (browser.equals("Chrome")) {
WebDriverManager.chromedriver().setup();
ChromeDriver driver = new ChromeDriver();
} else if (browser.equals("Edge")) {
WebDriverManager.edgedriver().setup();
EdgeDriver driver = new EdgeDriver();
}
driver.manage().window().maximize();
driver.get("https://www.flipkart.com/");
// Thread.sleep(5000);
// driver.findElement(By.className("_2KpZ6l _2doB4z")).click();
Thread.sleep(2000);
// Alert alert = (Alert) driver.switchTo().alert();
// alert.dismiss();
}
}
这是我尝试的代码
1条答案
按热度按时间tp5buhyn1#
而不是这样做
执行此操作
或