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

Webdriver - How to access to some specific iFrame through xpath/css

我无法通过以下网站中的 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>

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

请大家帮忙,谢谢。

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

  • 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 . See the A Better Approach to Switch Frames section.