我是Selenium网络驱动程序的新手。所以我想尝试使用不同的网站做一些示例。在这种模式下,我尝试与OTTO网站合作并尝试将项目添加到购物车。问题出现了,在这个网站上,在将项目添加到购物车之前有一个模态窗口。
我的问题是如何进入模态窗口并访问其中的元素?以下是我尝试过的代码。Click here to view the image for reference
import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class AutomationTesting {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","/Users/xxx/eclipse-workspace/seleniumTesting/lib/geckoDriver/geckodriver");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.de");
driver.findElement(By.id("lst-ib")).sendKeys("Pepe Jeans");
driver.findElement(By.id("lst-ib")).sendKeys(Keys.ENTER);
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.partialLinkText("Pepe Jeans Online-Shop | OTTO")));
driver.findElement(By.partialLinkText("Pepe Jeans Online-Shop | OTTO")).click();
driver.findElement(By.linkText("Pepe Jeans Chiffonkleid »MARY«, im modischen Leo-Muster")).click();
driver.findElement(By.xpath("//ul//li[@data-variationid='594838149']")).click();
driver.findElement(By.id("addToBasket")).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("p_layer")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("or_itemAdded__itemInfo")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@data-qa='goToBasket']")));
driver.findElement(By.xpath("//a[@data-qa='goToBasket']")).click();
}
}