【已解决】Selenium无法定位到iframe的动态ID

时间:2020-06-15 15:41:18   收藏:0   阅读:96

报错:selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

表现:无法定位到输入框

状态:已解决

备注:ch5_3.py 163邮箱登录页

参考:https://www.jianshu.com/p/5af3974c40c7   Selenium定位iframe动态ID

 

 

按照参考博客的方法,我将原本写的这个语句是用来定位非动态的iframe

1 driver.switch_to.frame(x-URS-iframe) 

但实际上我测试的页面使用的是动态ID,可以看到x-URS-iframe后面跟着的这一串数字

技术图片

因此需要把上面那行代码改成如下形式,用xpath定位属性值。

driver.switch_to.frame(driver.find_element_by_xpath("//iframe[starts-with(@id, ‘x-URS-iframe‘)]"))

 

xpath有三种方法定位动态ID,具体可见引用的原博客链接。感谢作者提供的方法。

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!