过时的元素异常,元素不可单击,元素单击被拦截,并且没有此类元素错误交替显示



我正在尝试使用自动化(Firefox(选择https://www.jabong.com/find/men's-black-jeans中可用的多个文件管理器。

但是,选择第一个选项(性别(后,我无法继续。

我面对元素点击被拦截并尝试流畅等待,这会导致过时的元素异常。

如果我删除 Fluent 等待或使用隐式等待,我有时会得到找到元素异常。

更令人困惑的是,有时代码无需等待即可正常运行,并且能够选择多个选项,但这很少见

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();
}

我刚刚尝试过,这段代码工作正常。

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();

相关内容

  • 没有找到相关文章

最新更新