I am trying to interact with an iframe video on a webpage. Here is the code snippet for the video:
<div class="videoWrapper" style="" xpath="1">
<iframe width="854" height="480" src="xxxxxxx" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen=""></iframe></div>
To switch to the frame containing the video, I used the following code:
driver.switchto().frame("videoWrapper");
I have tried two different approaches to play the video using JavaScript:
Approach 1 :
WebElement video = driver.findElement(By.xpath("//*[@id='player_uid_840828282_1']/div[4]/div[1]"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].play();", video);
Approach 2 :
JavascriptExecutor js = (JavascriptExecutor) driver;
js .executeScript("document.getElementById(\"video\").play()");
Unfortunately, neither of these methods seem to be working as expected. Can anyone provide insight into what might be going wrong here?