我无法通过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&spot_im_platform=desktop&host_url=https%3A%2F%2Fon.rt.com%2F90wm&host_url_64=aHR0cHM6Ly9vbi5ydC5jb20vOTB3bQ%3D%3D&spot_im_ph__prerender_deferred=true&prerenderDeferred=true&sort_by=best&isStarsRatingEnabled=false&enableMessageShare=true&enableAnonymize=false&isConversationLiveBlog=false&enableSeeMoreButton=true" scrolling="no" style="overflow: hidden; height: 2339px;" data-frame-unique-id="a6cbebb1116a32e10263270bfde7e0c1" data-conversation-id="sp_6phY2k0C_421078"></iframe>
我想将 key 发送到其中的输入元素 -
请您帮忙,谢谢。
最佳答案
您可以使用以下任一选项切换到特定框架:
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/