i need to click on the iframe video

2821 views javascript

i need to click on this iframe video,

<div class="videoWrapper"  xpath="1"> 
<iframe width="854" height="480" src="xxxxxxx" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen=""></iframe></div>

Code for switching to frame


i tried with these Logic's ,

Logic 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);

Logic 2 :

JavascriptExecutor js = (JavascriptExecutor) driver;
          js .executeScript("document.getElementById(\"video\").play()");

But it is not Working , please clear me this out guys!

answered question

Have you switched to iframe? Also why are you trying to call play() instead of click()? play is the method that applicable to video element, but not to iframe

yes , i tried like this, driver.switchto().frame("videoWrapper"); This is giving me error! and i tried to click (), it is not working so, i tried to call play()

driver.findElements(By.tagName("iframe")); then write your logic

driver.switchTo().frame(0); if u have two or more then 0,1,2...


videoWrapper is the style class of a div, not an iframe ID.

2 Answers


Try to use below code to switch to required frame:


posted this


posted this

Have an answer?


Please login first before posting an answer.