Java 如何使用selenium在magento购物车页面上等待期望值
在触发下一次单击事件之前,我尝试使用selenium webdriver等待购物车页面上计算的总计。但我有个例外。我在页面上没有其他可以等待的元素。我认为为经验丰富的开发人员找到解决方案真的很容易,但我不是那个 我使用这个等待命令:Java 如何使用selenium在magento购物车页面上等待期望值,java,selenium,xpath,css-selectors,webdriverwait,Java,Selenium,Xpath,Css Selectors,Webdriverwait,在触发下一次单击事件之前,我尝试使用selenium webdriver等待购物车页面上计算的总计。但我有个例外。我在页面上没有其他可以等待的元素。我认为为经验丰富的开发人员找到解决方案真的很容易,但我不是那个 我使用这个等待命令: wait.until(ExpectedConditions.textToBePresentInElementLocated(By.cssSelector(".grand.totals .price"), "35,75 €"));` 这是我试图选择元素的源代码片段
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 €</span></strong>
</td>
</tr>
Bestellsumme
35,75欧元
这是我得到的例外
org.openqa.selenium.ElementNotVisibleException:元素不可交互
(会话信息:chrome=75.0.3770.100)
(驱动程序信息:chromedriver=74.0.3729.6(255758ECCF3D24491B8A1317AA76E1CE10D57E9参考/分支头/3729{29}),平台=Windows NT 10.0.17134 x8664)(警告:服务器未提供任何堆栈跟踪信息)
命令持续时间或超时: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
看来你很接近。文本35,75€之间包含空格字符,并且位于
标记内。因此,您可以使用以下任一选项:
:css选择器
new WebDriverWait(driver, 20).until(ExpectedConditions.textToBePresentInElementLocated(By.cssSelector("tr.grand.totals td.amount>strong>span.price"), "35,75"));
:xpath
new WebDriverWait(driver, 20).until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//tr[@class='grand totals']//td[@class='amount']/strong/span[@class='price']"), "35,75"));
标记内。因此,您可以使用以下任一选项:
:css选择器
new WebDriverWait(driver, 20).until(ExpectedConditions.textToBePresentInElementLocated(By.cssSelector("tr.grand.totals td.amount>strong>span.price"), "35,75"));
:xpath
new WebDriverWait(driver, 20).until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//tr[@class='grand totals']//td[@class='amount']/strong/span[@class='price']"), "35,75"));