将鼠标悬停在图片上,然后将产品添加到购物车

时间:2017-10-19 18:02:03

标签: java selenium testing selenium-webdriver automation

当鼠标悬停在图像上时,我试图通过点击图标将两个产品添加到购物车中。如何首先选择图像然后将鼠标悬停在单击购物车上?

我的代码:

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("logout-trigger")));
driver.findElement(By.id("search-trigger")).sendKeys(Keys.ENTER);
driver.findElement(By.id("search")).sendKeys("Shampoo");
driver.findElement(By.id("search")).sendKeys(Keys.ENTER);
//Shampoos are displayed now i am going to get any of those and click on checkout 
driver.findElement(By.xpath(".//*[@id='product-listing']/grid-view-directive/section/div/div/div/div[1]/div/div[2]/div[6]/a/img")).sendKeys(Keys.ENTER);
Actions actions = new Actions(driver);
WebElement menuHoverLink = driver.findElement(By.xpath(".//*[@id='product-listing']/grid-view-directive/section/div/div/div/div[1]/div/div[2]/div[4]/div/a"));
actions.moveToElement(menuHoverLink);
actions.click();
actions.perform();  

HTML code:

For Image

<img class="img-responsive " alt="pClarifying ..."
     ng-src="https://web-examplestaging.com/cdn/images/ecommerce/products/thumbnails/Shmpoo_BIG_FLAT.png"
     ng-image-appear="" no-loader="" responsive="" bg-color="#ffffff"
     style="opacity: 1; transition: all 0.7s ease-in-out 0s; animation: 0.7s ease-in-out 0s normal none 1 running zoomIn;"
     src="https://example.com/cdn/images/ecommerce/products/thumbnails/Shampoo_BIG_FLAT.png">

for icon

<a title="Add to cart" href="javascript:void(0)" ng-mouseover="showgridViewToggle($index+1)"
   ng-click="helperService.addToCart('grid_product',prod.productSizeId,$index+1,prod.itemsPerBox)">
    <i class="fa fa-shopping-bag faa-shake animated"></i>
</a>

0 个答案:

没有答案