在 Firefox 中执行以下测试时,org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with会抛出“”。原因似乎是在使用 Select 字段(变量 selectMarke)之前出现的弹出窗口(奇怪的是,在手动单击该站点时不会出现)。我尝试了几种在不同线程中列出的可能性,但没有奏效。原因似乎是弹出窗口。
我该如何解决这个问题?
    FirefoxProfile profile = new FirefoxProfile();
    profile.setEnableNativeEvents(true);
    WebDriver driver = new FirefoxDriver(profile);
    driver.manage().timeouts().implicitlyWait(16, TimeUnit.SECONDS);
    driver.get("http://www.autoscout24.de/");
    System.out.println("Page title is: " + driver.getTitle());
    WebElement pageWSuche = driver.findElement(By.linkText("Werkstattsuche"));
    pageWSuche.click();
    WebElement plzField = driver.findElement(By.id("cms-plz"));
    plzField.sendKeys("81243");
    WebElement findGarField = driver.findElement(By.cssSelector("span.buttonBob span input[value='Werkstätten finden']"));
    findGarField.click();
    WebElement navInspect = driver.findElement(By.linkText("Inspektion (mit Preis)"));
    navInspect.click();
    Select selectMarke = new Select(driver.findElement(By.cssSelector("select.inputL[name='MakeId']")));
    selectMarke.selectByVisibleText("BMW");
    driver.quit();
在同一域但在不同页面中执行以下类时,一切都很好,因为不会出现弹出窗口。
    FirefoxProfile profile = new FirefoxProfile();
    profile.setEnableNativeEvents(true);
    WebDriver driver = new FirefoxDriver(profile);
    driver.manage().timeouts().implicitlyWait(16, TimeUnit.SECONDS);
    driver.get("http://www.autoscout24.de/");
    WebElement element = driver.findElement(By.linkText("Fahrzeugsuche"));
    element.click();
    Select selectMarke = new Select(driver.findElement(By.cssSelector("select.inputFullWidth[name='make1']")));
    selectMarke.selectByVisibleText("BMW");
    Select selectModell = new Select(driver.findElement(By.cssSelector("select.inputFullWidth[name='model1']")));
    selectModell.selectByValue("15779");
    Select selectPriceTo = new Select(driver.findElement(By.cssSelector("select.inputFullWidth[name='priceto']")));
    selectPriceTo.selectByVisibleText("100.000");
    Select selectYearFrom = new Select(driver.findElement(By.cssSelector("select.inputFullWidth[name='yearfrom']")));
    selectYearFrom.selectByVisibleText("2006");
    Select selectKM = new Select(driver.findElement(By.cssSelector("select.inputFullWidth[name='mileageto']")));
    selectKM.selectByVisibleText("200.000");
    Select selectFuel = new Select(driver.findElement(By.cssSelector("select.inputFullWidth[name='fuel']")));
    selectFuel.selectByVisibleText("Diesel");
    WebElement location = driver.findElement(By.id("zipcode"));
    location.sendKeys("München");
    Select selectRadius = new Select(driver.findElement(By.cssSelector("select.inputFullWidth[name='zipradius']")));
    selectRadius.selectByVisibleText("200 km");
    WebElement searchBtn = driver.findElement(By.cssSelector("input[value$='Fahrzeuge']"));
    searchBtn.click();
    driver.quit();