【发布时间】:2021-06-29 13:18:49
【问题描述】:
我有一个想要切换到的 iFrame,但 iFrame 每次都会生成一个随机 ID。如何切换到此 iFrame。据我所知,资源保持一致。
更新:点击下载有效,但点击关闭无效。
<iframe id="e674" src="/resource.ashx/636625958320000000/du/webviewer/html5/Reader.html?setLng=en#d=%2Fdocumentviewer.ashx%2FDownloadDocument%3FstateId%3Dv3x4o%26cacheInfoKey%3D1arhoq9%2F1arhoq9-1o5aabb.json&auto_load=false&languageUrl=%2Fresource.ashx%2F636625958320000000%2Fdu%2Flocalization.json%3Fdisplay%3D__lng__&custom=%7B%22permissions%22%3A65535%2C%22showToolbar%22%3Atrue%2C%22showSidePane%22%3Atrue%2C%22singlePageRotation%22%3Afalse%2C%22downloadUrl%22%3A%22%2Fdocumentviewer.ashx%2FDownloadSource%3FstateId%3Dv3x4o%26cacheInfoKey%3D1arhoq9%2F1arhoq9-1o5aabb.json%22%2C%22downloadAsPdfUrl%22%3A%22%2Fdocumentviewer.ashx%2FDownloadAsPdf%3FstateId%3Dv3x4o%26cacheInfoKey%3D1arhoq9%2F1arhoq9-1o5aabb.json%22%7D&filepicker=0&preloadWorker=1&pdfnet=0&pageHistory=1&subzero=1" frameborder="0" width="100%" height="100%" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true"></iframe>
driver.switch_to.frame(driver.find_element_by_xpath("//iframe[@name='rwDocumentviewer']"))
time.sleep(3)
driver.switch_to.frame(driver.find_element_by_xpath("//iframe[contains(@src,'webviewer/html5/Reader.html')]"))
#Click on download
downloadButton = driver.find_element_by_xpath('//*[@id="downloadButton"]')
downloadButton.click()
time.sleep(3)
#Click on close
closeButton = driver.find_element_by_xpath('//*[@id="btnZorgAnnuleren"]')
closeButton.click()
driver.switch_to.default_content()
【问题讨论】:
-
我投票结束这个问题,因为这里被问到stackoverflow.com/questions/68176797/…
-
这是一个不同的问题,因为我在这里讨论如何处理动态 iFrame (ID)。
-
我也对该帖子发表了评论。如果没有解决,请告诉我们出了什么问题以及为什么需要这个问题。如果它看起来很真实,我自己肯定也会看看这个问题
-
对不起,我对 SO 有点陌生。当你有一个新问题时,我以为你应该开始一个新帖子。抱歉!
-
我明白,但是当有人回答你的问题时,你可以评论它是否有效,我认为这也和这个问题一样。