我如何使用硒等待 magento 购物车页面上的预期值

在触发下一个点击事件之前,我尝试使用 selenium webdriver 等待购物车页面上的计算总计。但我有一个例外。我可以等待的页面上没有其他元素。我认为为有经验的开发人员找到解决方案真的很容易,但我不是那个人。


我使用这个等待命令:


wait.until(ExpectedConditions.textToBePresentInElementLocated(By.cssSelector(".grand.totals .price"), "35,75 €"));`

这是我尝试选择元素的源代码片段。


<tr class="grand totals">

    <th class="mark" scope="row">

        <strong data-bind="i18n: title">Bestellsumme</strong>

    </th>

    <td data-bind="attr: {'data-th': title}" class="amount" data-th="Bestellsumme">

        <strong><span class="price" data-bind="text: getValue()">35,75&nbsp;€</span></strong>

    </td>

</tr>

这是我得到的例外。


org.openqa.selenium.ElementNotVisibleException:元素不可交互(会话信息:chrome=75.0.3770.100)(驱动程序信息:chromedriver=74.0.3729.6(255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729),@=平台NT 10.0.17134 x86_64)(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:0 毫秒构建信息:版本:'3.141.59',修订:'e82be7d358',时间:'2018-11-14T08 :17:03' 系统信息:主机:'MARCEL-THINK',ip:'10.110.12.3',os.name:'Windows 10',os.arch:'amd64',os.version:'10.0',java .version: '11.0.3' 驱动程序信息:org.openqa.selenium.chrome.ChromeDriver


拉风的咖菲猫
浏览 71回答 1
1回答

料青山看我应如是

看来你很亲密。文本35,75 €在中间包含一个空格字符,并且位于<span>标记内。因此,您可以使用以下任一定位器策略:cssSelector:new&nbsp;WebDriverWait(driver,&nbsp;20).until(ExpectedConditions.textToBePresentInElementLocated(By.cssSelector("tr.grand.totals&nbsp;td.amount>strong>span.price"),&nbsp;"35,75"));xpath:new&nbsp;WebDriverWait(driver,&nbsp;20).until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//tr[@class='grand&nbsp;totals']//td[@class='amount']/strong/span[@class='price']"),&nbsp;"35,75"));
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java