在觸發下一個點擊事件之前,我嘗試使用 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 €</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
1 回答

料青山看我應如是
TA貢獻1772條經驗 獲得超8個贊
看來你很親密。文本35,75 €在中間包含一個空格字符,并且位于<span>
標記內。因此,您可以使用以下任一定位器策略:
cssSelector
: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"));
添加回答
舉報
0/150
提交
取消