我正在尝试使用Automation(Firefox)选择https://www.jabong.com/find/men's-black-jeans中可用的多个文件管理器。
但是,选择第一个选项(性别)后,我无法继续。
我遇到了元素点击被拦截的问题,并尝试了Fluent Wait,导致过时的元素异常。
如果我删除Fluent等待或使用隐式等待,有时会发现Element found异常。
为了增加混乱,有时代码可以正常运行而无需等待,并且能够选择多个选项,但这很少见
public void case9() {
driver.get("https://www.jabong.com/");
WebElement SearchBox = driver.findElement(By.xpath("//*[@id=\"search\"]"));
SearchBox.sendKeys("men's black jeans");
Actions actn = new Actions (driver);
actn.sendKeys(SearchBox, Keys.ENTER).build().perform();
driver.manage().timeouts().implicitlyWait(34, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id=\"allFilterPopupTop\"]")).click();
driver.manage().timeouts().implicitlyWait(34, TimeUnit.SECONDS);
driver.findElement(By.xpath("/html/body/section[1]/div/section/section[1]/div/div[2]/div[2]/ul/li[1]/div[3]/div/div[2]/label[1]/div/input")).click();
driver.findElement(By.xpath("//*[@id=\"Brand\"]")).click();
WebDriverWait wait1 = new WebDriverWait(driver,61);
WebElement brand1 =
driver.findElement(By.xpath("xpath for element"));
wait1.until(ExpectedConditions.elementToBeClickable(brand1));
brand1.click();
driver.findElement(By.xpath("xpath for element")).click();
driver.findElement(By.xpath("//[@id=\"Global_Size\"]")).click();
WebElement Size =
driver.findElement(By.xpath("xpath for element"));
wait1.until(ExpectedConditions.elementToBeClickable(Size));
Size.click();
driver.findElement(By.xpath("//*[@id=\"Fit\"]")).click();
driver.manage().timeouts().implicitlyWait(61, TimeUnit.SECONDS);
driver.findElement(By.xpath("xpath for element")).click();
driver.findElement(By.xpath("//*[@id=\"Fade\"]")).click();
driver.manage().timeouts().implicitlyWait(61, TimeUnit.SECONDS);
[@id=\"applyFIlters\"]")).click();
}
答案 0 :(得分:0)
我刚刚尝试过,此代码可以正常工作。
driver.get("https://www.jabong.com/");
WebElement searchBox = driver.findElement(By.cssSelector("#search"));
searchBox.sendKeys("men's black jeans");
WebElement searchIcon = driver.findElement(By.cssSelector("#top-search-input > div.search-containter > span"));
searchIcon.click();
WebElement firstCheckBox = driver.findElement(By.id("boys"));
firstCheckBox.click();