英文:
Not able to locate an element inside an iFrame using selenium
问题
public boolean checkVideoLoad() throws InterruptedException
{
try
{
WebElement frame = driver.findElement(By.xpath("//iframe[contains(@id,'video-player-container_ifp')]"));
driver.switchTo().frame(frame);
Thread.sleep(1000);
driver.findElement(By.xpath("//div[contains(@class,'videoHolder hover')]//a[contains(@class,'icon-play comp largePlayBtn largePlayBtnBorder')]")).click();
Thread.sleep(12000);
driver.switchTo().defaultContent();
return true;
}
catch(NoSuchElementException ne)
{
Assert.assertNull(ne, "Unable to play video in the development phase. For QA-check the function checkVideoLoad");
return false;
}
}
<iframe id="video-player-container_ifp" scrolling="no" name="video-player-container_ifp" class="mwEmbedKalturaIframe" title="The Kaltura Dynamic Video Player" frameborder="0" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true" allow="autoplay *; fullscreen *; encrypted-media *" style="border: 0px; max-width: 100%; max-height: 100%; width: 100%; height: 100%;" cd_frame_id_="85841ea4374782c35e034f22ddc9e7fb"></iframe>
<div class="videoHolder hover">
<div class="videoDisplay">
<video class="persistentNativePlayer nativeEmbedPlayerPid" poster="data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%01%00%00%00%01%08%02%00%00%00%90wS%DE%00%00%00%01sRGB%00%AE%CE%1C%E9%00%00%00%09pHYs%00%00%0B%13%00%00%0B%13%01%00%9A%9C%18%00%00%00%07tIME%07%DB%0B%0A%17%041%80%9B%E7%F2%00%00%00%19tEXtComment%00Created%20with%20GIMPW%81%0E%17%00%00%00%0CIDAT%08%D7c%60%60%60%00%00%00%04%00%01'4'%0A%00%00%00%00IEND%AEB%60%82" id="pid_video-player-container" kentryid="0_hkycisyi" kuiconfid="42816162" kwidgetid="_2413672" kpartnerid="2413672" preload="none" width="898" height="480" src="https://cdnapisec.kaltura.com/p/2413672/sp/241367200/playManifest/entryId/0_hkycisyi/flavorId/0_tvsaqyid/format/url/protocol/https/a.mp4?referrer=aHR0cHM6Ly9zdGctYWt0aXZwbGF0Zm9ybS5rbm9sc2thcGUuaW8&playSessionId=0d66f89c-7899-dfc5-4112-c78c1943c6b8&clientTag=html5:v2.79.1&uiConfId=42816162" style="position: absolute;"></video>
<div class="videoShadow"></div>
<div class="mwEmbedPlayer mwEmbedPlayerBlackBkg" id="video-player-container">
<img src="https://cfvod.kaltura.com/p/2413672/sp/241367200/thumbnail/entry_id/0_hkycisyi/version/100002/width/898/height/480" class="playerPoster fill-width" alt="Video thumbnail for wonderduck.mp4">
</div>
</div>
<a tabindex="-1" href="#" role="button" class="icon-play comp largePlayBtn largePlayBtnBorder" aria-label="Play clip" data-order="1" data-plugin-name="largePlayBtn" style="background-color: rgb(0, 0, 0) !important; color: rgb(255, 255, 255) !important; display: block;"></a>
</div>
英文:
Im trying to access a video item which is there inside an iframe, but the play button for the video is not getting identified in the latest chroem version(80), though the same logic was working in the older versions.
everytime for the element inside athe iframe it is giving no such elemet found exception
this is the logic im trying with:
public boolean checkVideoLoad() throws InterruptedException
{
try
{
WebElement frame=driver.findElement(By.xpath("//iframe[contains(@id,'video-player-container_ifp')]"));
driver.switchTo().frame(frame);
Thread.sleep(1000);
driver.findElement(By.xpath("//div[contains(@class,'videoHolder hover')]//a[contains(@class,'icon-play comp largePlayBtn largePlayBtnBorder')]")).click();
Thread.sleep(12000);
driver.switchTo().defaultContent();
return true;
}
catch(NoSuchElementException ne)
{
Assert.assertNull(ne, "Unable to play video in the development phase. For QA-check the function checkVideoLoad");
return false;
}
}
this is the error post execution
Exception in thread "main" org.openqa.selenium.InvalidArgumentException: invalid argument: Unsupported locator strategy: null
(Session info: chrome=80.0.3987.163)
Also when js-executor is used to identify and perform the click opertaion on the element it is thrwing :
Exception in thread "main" org.openqa.selenium.JavascriptException: javascript error: Cannot read property 'click' of null
even when the same js code is working fine in the console
this is the html of the iframe
<iframe id="video-player-container_ifp" scrolling="no" name="video-player-container_ifp" class="mwEmbedKalturaIframe" title="The Kaltura Dynamic Video Player" frameborder="0" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true" allow="autoplay *; fullscreen *; encrypted-media *" style="border: 0px; max-width: 100%; max-height: 100%; width: 100%; height: 100%;" cd_frame_id_="85841ea4374782c35e034f22ddc9e7fb"></iframe>
<div class="videoHolder hover"><div class="videoDisplay">
<video class="persistentNativePlayer nativeEmbedPlayerPid" poster="data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%01%00%00%00%01%08%02%00%00%00%90wS%DE%00%00%00%01sRGB%00%AE%CE%1C%E9%00%00%00%09pHYs%00%00%0B%13%00%00%0B%13%01%00%9A%9C%18%00%00%00%07tIME%07%DB%0B%0A%17%041%80%9B%E7%F2%00%00%00%19tEXtComment%00Created%20with%20GIMPW%81%0E%17%00%00%00%0CIDAT%08%D7c%60%60%60%00%00%00%04%00%01'4'%0A%00%00%00%00IEND%AEB%60%82" id="pid_video-player-container" kentryid="0_hkycisyi" kuiconfid="42816162" kwidgetid="_2413672" kpartnerid="2413672" preload="none" width="898" height="480" src="https://cdnapisec.kaltura.com/p/2413672/sp/241367200/playManifest/entryId/0_hkycisyi/flavorId/0_tvsaqyid/format/url/protocol/https/a.mp4?referrer=aHR0cHM6Ly9zdGctYWt0aXZwbGF0Zm9ybS5rbm9sc2thcGUuaW8=&amp;playSessionId=0d66f89c-7899-dfc5-4112-c78c1943c6b8&amp;clientTag=html5:v2.79.1&amp;uiConfId=42816162" style="position: absolute;"></video><div class="videoShadow"></div><div class="mwEmbedPlayer mwEmbedPlayerBlackBkg" id="video-player-container" style=""><img src="https://cfvod.kaltura.com/p/2413672/sp/241367200/thumbnail/entry_id/0_hkycisyi/version/100002/width/898/height/480" class="playerPoster fill-width" alt="Video thumbnail for wonderduck.mp4"></div>
</div><a tabindex="-1" href="#" role="button" class="icon-play comp largePlayBtn largePlayBtnBorder" aria-label="Play clip" data-order="1" data-plugin-name="largePlayBtn" style="background-color: rgb(0, 0, 0) !important; color: rgb(255, 255, 255) !important; display: block;"></a></div>
专注分享java语言的经验与见解,让所有开发者获益!
评论