node.js - Webdriver - 如何通过 xpath/css 访问某些特定的 iFrame

标签 node.js selenium-webdriver automation mocha.js frontend

我无法通过selenium(node js + mocha)访问下面网站中的某些iFrame -

https://www.rt.com/uk/421078-may-skripal-russia-parliament/

所需的 iframe 元素 -

<iframe id="5645d42cb79d139a24d943622da2c47d-iframe" src="https://spoxy-shard5.spot.im/v2/spot/sp_6phY2k0C/post/421078/?elementId=b2ec2c94ee1c35810c76e1704dbe3d06&amp;spot_im_platform=desktop&amp;host_url=https%3A%2F%2Fon.rt.com%2F90wm&amp;host_url_64=aHR0cHM6Ly9vbi5ydC5jb20vOTB3bQ%3D%3D&amp;spot_im_ph__prerender_deferred=true&amp;prerenderDeferred=true&amp;sort_by=best&amp;isStarsRatingEnabled=false&amp;enableMessageShare=true&amp;enableAnonymize=false&amp;isConversationLiveBlog=false&amp;enableSeeMoreButton=true" scrolling="no" style="overflow: hidden; height: 2339px;" data-frame-unique-id="a6cbebb1116a32e10263270bfde7e0c1" data-conversation-id="sp_6phY2k0C_421078"></iframe>

我想将 key 发送到其中的输入元素 -

enter image description here

请您帮忙,谢谢。

最佳答案

您可以使用以下任一选项切换到特定框架:

  • CSS:

    iframe[id$='-iframe'][src^='https://spoxy-shard5.spot.im/v2/spot/sp_']
    
  • XPATH:

    //iframe[contains(@id,'-iframe') and starts-with(@src,'https://spoxy-shard5.spot.im/v2/spot/sp_')]
    

Note : You may require to induce wait for the intended frame to be available and switch to it. You will find a detailed discussion in How can I select a html element no matter what frame it is in in selenium?. See the A Better Approach to Switch Frames section.

关于node.js - Webdriver - 如何通过 xpath/css 访问某些特定的 iFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49280713/

相关文章:

java - 使用 webdriver 找不到元素

testing - QTP:如何处理在不确定时间出现的弹出窗口

java - 如何在 try-catch block 中使用 .click() 命令 java android

json - 在 Node.js/Express 中记录所有请求

node.js - 如何将特殊字符放入 apollo graphQL 服务器的枚举值中?

javascript - 错误! enoent 并且与 npm 无法找到文件有关

java - 对于并发测试执行,WebDriver 设置应该是静态的吗?

javascript - 如何从 Java 中的 JavascriptExecutor.executeScript() 方法返回值

gwt - 如何将自动监控/服务集成到 gwt 应用程序中?

javascript - 无法理解 react 依赖中的问题