我需要等到javascript匹配字符串或布爾值的結果。Selenium - 等到返回的JavaScript腳本值匹配值
憑藉此javascript:
document.getElementById('video_html5').seeking;
我得到一個「假」 /「真」值,我需要等到值是「假的」,所以我敢肯定,視頻是不是尋求,但我只找到了等待javascript命令值的方法,而不是檢查值是否與某些文本匹配的方式。
new WebDriverWait(driver, 30)
.until(ExpectedConditions.jsReturnsValue("return document.getElementById('video_html5').seeking;"));
因爲在某些情況下,我得到一個非布爾值的字符串,並且需要比較這些字符串。
我發現如何做到這一點的Ruby,但沒有在Java中:
wait_element = @wait.until { @driver.execute_script("return document.getElementById('vid1_html5_api_Shaka_api').seeking;").eql? false }
這工作? 'jsReturnsValue(「document.getElementById('video_html5')。seeking ==='false'?'true':undefined;」)它會直接在JavaScript中比較值,如果seek爲true則返回undefined。 –