无法使用硒在iFrame中定位元素

时间:2020-04-06 10:53:10

标签: java selenium iframe nosuchelementexception

我正在尝试访问iframe内的视频项目,但是在最新的Chroem版本(80)中未标识视频的播放按钮,尽管在旧版本中也使用了相同的逻辑。 每次在iframe中的元素都没有给出此类图元发现的异常

这是我尝试使用的逻辑:

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;
    }
}

这是执行后的错误

Exception in thread "main" org.openqa.selenium.InvalidArgumentException: invalid argument: Unsupported locator strategy: null

(会话信息:chrome = 80.0.3987.163) 同样,当使用js-executor来识别和执行对其抛出的元素的点击操作时:

Exception in thread "main" org.openqa.selenium.JavascriptException: javascript error: Cannot read property 'click' of null

即使相同的js代码在控制台中运行正常

这是iframe的html

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

0 个答案:

没有答案