无法使用Selenium定位iFrame内的元素。

huangapple 未分类评论49阅读模式
英文:

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&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">
            <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(&quot;//iframe[contains(@id,&#39;video-player-container_ifp&#39;)]&quot;));
		driver.switchTo().frame(frame);
		Thread.sleep(1000);
		driver.findElement(By.xpath(&quot;//div[contains(@class,&#39;videoHolder hover&#39;)]//a[contains(@class,&#39;icon-play  comp largePlayBtn  largePlayBtnBorder&#39;)]&quot;)).click();
		Thread.sleep(12000);
		driver.switchTo().defaultContent();
		return true;
	}
	catch(NoSuchElementException ne)
	{
		Assert.assertNull(ne, &quot;Unable to play video in the development phase. For QA-check the function checkVideoLoad&quot;);
		return false;
	}
}

this is the error post execution

Exception in thread &quot;main&quot; 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 &quot;main&quot; org.openqa.selenium.JavascriptException: javascript error: Cannot read property &#39;click&#39; of null

even when the same js code is working fine in the console

this is the html of the iframe

&lt;iframe id=&quot;video-player-container_ifp&quot; scrolling=&quot;no&quot; name=&quot;video-player-container_ifp&quot; class=&quot;mwEmbedKalturaIframe&quot; title=&quot;The Kaltura Dynamic Video Player&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;true&quot; webkitallowfullscreen=&quot;true&quot; mozallowfullscreen=&quot;true&quot; allow=&quot;autoplay *; fullscreen *; encrypted-media *&quot; style=&quot;border: 0px; max-width: 100%; max-height: 100%; width: 100%; height: 100%;&quot; cd_frame_id_=&quot;85841ea4374782c35e034f22ddc9e7fb&quot;&gt;&lt;/iframe&gt;

&lt;div class=&quot;videoHolder hover&quot;&gt;&lt;div class=&quot;videoDisplay&quot;&gt; 

&lt;video class=&quot;persistentNativePlayer nativeEmbedPlayerPid&quot; poster=&quot;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&#39;4&#39;%0A%00%00%00%00IEND%AEB%60%82&quot; id=&quot;pid_video-player-container&quot; kentryid=&quot;0_hkycisyi&quot; kuiconfid=&quot;42816162&quot; kwidgetid=&quot;_2413672&quot; kpartnerid=&quot;2413672&quot; preload=&quot;none&quot; width=&quot;898&quot; height=&quot;480&quot; src=&quot;https://cdnapisec.kaltura.com/p/2413672/sp/241367200/playManifest/entryId/0_hkycisyi/flavorId/0_tvsaqyid/format/url/protocol/https/a.mp4?referrer=aHR0cHM6Ly9zdGctYWt0aXZwbGF0Zm9ybS5rbm9sc2thcGUuaW8=&amp;amp;playSessionId=0d66f89c-7899-dfc5-4112-c78c1943c6b8&amp;amp;clientTag=html5:v2.79.1&amp;amp;uiConfId=42816162&quot; style=&quot;position: absolute;&quot;&gt;&lt;/video&gt;&lt;div class=&quot;videoShadow&quot;&gt;&lt;/div&gt;&lt;div class=&quot;mwEmbedPlayer mwEmbedPlayerBlackBkg&quot; id=&quot;video-player-container&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://cfvod.kaltura.com/p/2413672/sp/241367200/thumbnail/entry_id/0_hkycisyi/version/100002/width/898/height/480&quot; class=&quot;playerPoster fill-width&quot; alt=&quot;Video thumbnail for wonderduck.mp4&quot;&gt;&lt;/div&gt;

</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>

huangapple
  • 本文由 发表于 2020年4月6日 18:53:10
  • 转载请务必保留本文链接:https://java.coder-hub.com/61058132.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定