1

I have a webpage where there is a video, i want to find that video duration and play that video to 10% of the total time.

I am new to Selenium and searched on google but unable to find the solution. Please help.

Thanks in advance.

2

i am giving the generic answer, kindly try on it

Webdriver Element = driver.findElement(By.Id("Id of the frame"));
Switch into the frame driver.switchTo().frame(Element);
driver.findElement(By.Id("Element of of play button"))

use the action class to mouseover and capture the duration time

Actions builder = new Actions(driver);
        WebElement we = driver.findElement(By.id("movie_player"));
        Action mouseMovement=builder.moveToElement(we).build();
        mouseMovement.perform();

        WebElement durationTime= wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(enter the path)));
  • convert the durationtime into sec
  • calculate the percentage
  • base on that percentage click on the navigation bar.
1
  • 1
    If you're going to copy the code from another answer word-for-word, then you should use the same webdriver variable driver instead of driver1 for consistency purposes. Mar 30 '18 at 13:06
0

To answer to your first question.

Webdriver Element = driver.findElement(By.Id("Id of the frame"));

//Switch into the frame
driver.switchTo().frame(Element);

//Click on play button
driver.findElement(By.Id("Element of of play button"))

Second question will search and update here.

0
*

WebDriver driver=new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.manage().window().maximize();
    driver.get("https://www.wonderplugin.com/wordpress-lightbox");
    WebElement element=driver.findElement(By.xpath("//a[contains(text(),'Open a Div in Lightbox')]"));
    element.click();
    System.out.println("found element and clicked");
    Thread.sleep(3000);
WebElement frameElement=driver.findElement(By.xpath("//iframe[@src='https://www.youtube.com/embed/wswxQ3mhwqQ']"));
driver.switchTo().frame(frameElement);
        driver.findElement(By.xpath("//button[@aria-label=\'Play\']")).click();
        Actions builder = new Actions(driver);
        WebElement we = driver.findElement(By.className("ytp-progress-bar-container"));
        Action mouseMovement=builder.moveToElement(we).build();
        mouseMovement.perform();
        we.click();
        WebDriverWait wait = new WebDriverWait(driver, 20);
        WebElement titleText=wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("ytp-title-link")));
        System.out.println(titleText.getText());
        WebElement time=wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("span.ytp-time-current")));
        System.out.println(time.getText());

*

1
  • Please add the explanation of your answer. Jun 24 '19 at 6:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.