如果错误显示元素无法点击,您如何点击购物车图标? 我已经尝试过使用inspect元素,但无济于事。我已经这样做了一个小时,我仍然没有得到如何点击购物车图标。如果那不是购物车图标的元素,那么它是什么?非常感谢。我是stackoverflow的新手。
driver.get("http://www.metromart.com");
driver.findElement(By.cssSelector(".hover-green")).click();
driver.findElement(By.cssSelector("#ember781")).sendKeys("deumdummy@yahoo.com");
driver.findElement(By.cssSelector("#ember783")).sendKeys("password");
driver.findElement(By.cssSelector("button.btn.green.block")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.xpath("//span[contains(@style,'background-image: url(https://metromart3.imgix.net/shops/5/logo.png?ixlib=rb-1.0.0)')]")).click();
WebElement element = driver.findElement(By.cssSelector(".btn.green.medium"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().perform();
driver.findElement(By.xpath("//img[@alt='Acana Duck And Bartlett Pear Singles Formula']")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.cssSelector("a.btn.green.huge.block")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.cssSelector(".ember-view.cart-icon")).click();
WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".btn.green.jumbo]")));
答案 0 :(得分:0)
试试这个:
new WebDriverWait(driver, 10).until(ExpectedConditions
.presenceOfElementLocated(By.cssSelector(".ember-view.cart-icon")));
driver.findElement(By.cssSelector(".ember-view.cart-icon")).click();