我不得不在购物车中添加洗发水
它工作正常
但现在不是
他们的代码没有变化
现在它向下滚动页面并停止工作
以下是我的代码
directory of build.xml - "D:\xxx\Trunk\build.xml"
directory of batchfile.bat - "D:\xxx\Trunk\Batch\batchfile.bat"
网络代码
driver.findElement(By.id("submit")).sendKeys(Keys.ENTER);
WebDriverWait wait = new WebDriverWait (driver, 10);
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);
driver.findElement(By.id("grid_quantity_1")).sendKeys(Keys.ENTER);
Actions actions = new Actions(driver);
WebElement menuHoverLink = driver.findElement(By.linkText("Add to cart"));
actions.moveToElement(menuHoverLink);
actions.click();
actions.perform();
我在日食上得到的东西
<div class="grid-add-to-cart" ng-show="prod.currentPrice > 0" ng-mouseleave="hidegridViewToggle($index+1)">
<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>
<div class="grid-quantity-field" id="show_grid_input_div_1">
<input ng-keypress="($event.which===13)?helperService.addToCart('grid_product',prod.productSizeId,$index+1,prod.itemsPerBox):helperService.keyCheck($event)" type="number" name="quantity" id="grid_quantity_1" data-ng-class="$even ? 'height_80' : ''" oninput="maxLengthCheck(this)" ng-model="prod.itemsPerBoxInput" maxlength="5" min="1" max="99999" ng-value="userType == 'distributor' ? 6: 1" title="Add Quantity" class="ng-pristine ng-valid ng-valid-min ng-valid-max ng-valid-maxlength height_80 ng-touched" value="1" style="">
</div>
</div>
答案 0 :(得分:0)
参考您分享的HTML
,您有以下内容:
driver.findElement(By.linkText("Add to cart"));
似乎需要在xpath
中进行一些修改。您可以尝试使用以下代码行:
WebElement menuHoverLink = driver.findElement(By.xpath("//a[@title='Add to cart']"));