【问题标题】:Close pop up within iframe using Selenium and VBA使用 Selenium 和 VBA 在 iframe 中关闭弹出窗口
【发布时间】:2021-12-15 03:08:15
【问题描述】:

我想下载视频,但是有问题
我正在尝试关闭弹出窗口

我使用的代码无效
这是我的代码

Sub Close_Pop_up()
    With New ChromeDriver
        .Get "https://snaptik.app/en/"
        .FindElementById("url").SendKeys ("https://www.tiktok.com/@funny_v.i.p/video/7020796826760547590")
        .FindElementById("submiturl").Click
        .FindElementByXPath("/html/body/main/section[2]/div/div/article/div[2]/div/a[1]/span/span").Click
        .SwitchToFrame .FindElementByTag("iframe", TimeOut:=10000)
        .FindElementById("dismiss-button").Click
    End With
End Sub

这是html代码

<div class="ns-dws4v-e-6 close-button" id="dismiss-button" x-ns-dws4v-e="6" x-overflow-forbidden="xy" aria-label="Close ad" tabindex="1"><div class="ns-dws4v-e-7 close-text" x-ns-dws4v-e="7"><span class="ns-dws4v-e-8" dir="auto" x-ns-dws4v-e="8" x-score="1">Close</span></div></div>

谁能给出一个好主意?

【问题讨论】:

  • has not worked 意味着什么?你收到错误信息了吗?什么都没发生吗? ......
  • 找不到 id=dismiss-button 的元素
  • 您确定要切换吗?

标签: excel vba selenium iframe


【解决方案1】:

页面内共有12ifames,您需要确定您打算切换的具体iframe

解决方案

Sub Close_Pop_up()
    With New ChromeDriver
    .Get "https://snaptik.app/en/"
    .FindElementById("url").SendKeys ("https://www.tiktok.com/@funny_v.i.p/video/7020796826760547590")
    .FindElementById("submiturl").Click
    .FindElementByXPath("/html/body/main/section[2]/div/div/article/div[2]/div/a[1]/span/span").Click
    .SwitchToFrame "ad_iframe"

【讨论】:

猜你喜欢
  • 2020-06-22
  • 1970-01-01
  • 2021-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-04
  • 1970-01-01
相关资源
最近更新 更多