无法使用Javascript设置视频的当前时间

时间:2018-11-28 02:35:03

标签: javascript

有时设置当前时间的JavaScript不起作用。但是当我得到当前时间时,时间就是我设定的时间。这个问题有解决方案吗?

代码:

JavascriptExecutor js = (JavascriptExecutor) driver;
Long timeR2 = (long) 0;
int tmp = 0;
if (timeR2 != null) 
{
boolean flag = false;
int tV = (int) (timeR2 - 2) / 2;
int i = 0;
int j = 2;
Long val = (long) 0;
Long temp = (long) 0;
for (String w : words) {
    while (tmp < 600 || val != 0) {
        if (val == 0) {
            Thread.sleep(100);
            tmp++;
        }
        boolean check = (boolean) js.executeScript("return (document.querySelector('video').paused);");
        val = (Long) js.executeScript(
                                      "return Math.floor(document.querySelector('video').currentTime);");
        if (val == tV * i + 1 || val == tV * i + j) {                             
            WebElement webElement = driver.findElement(By.xpath(
                                                                "//*[@class='eq-center-icon-pause']|//*[@class='eq-icon-pause eq-landscape']"));
            js.executeScript("arguments[0].click();", webElement);
            Thread.sleep(1000);

            //Sometimes don't work
            js.executeScript("document.querySelector('video').currentTime='" +( tV * i + 1 )+ "';");
            //Sometimes don't work

            temp = (Long) js.executeScript(
                    "return Math.round(document.querySelector('video').currentTime);");
            System.out.println(temp);
            while(temp!= tV * i + 1) {
                js.executeScript("document.querySelector('video').currentTime='" +( tV * i + 1 )+ "';");
                temp = (Long) js.executeScript(
                        "return Math.round(document.querySelector('video').currentTime);");
            }
            tmp = 0;
            Thread.sleep(2000);
            break;
        }
    }
}

}

硒:3.141.59

浏览器:Edge(版本42)

窗口10

0 个答案:

没有答案