簡體   English   中英

如何使用 Selenium VBA 關閉彈出窗口

[英]How to close popup using Selenium VBA

我一直在嘗試關閉打開鏈接時出現的彈出窗口。

我嘗試使用 Xpath 單擊彈出窗口上的關閉按鈕,但代碼不斷打開一個新頁面,顯然單擊了錯誤的鏈接。

這是我正在嘗試的代碼。

Public Sub scrapeCIL2()
    Dim bot As New WebDriver, btn As Object, i As Long, pageCount As Long

    Dim wins As Variant



    bot.Start "chrome", "https://duproprio.com/en/search/list?search=true&regions%5B0%5D=6&is_for_sale=1&with_builders=1&parent=1&pageNumber=2&sort=-published_at"
    bot.Get "/"
    pageCount = bot.FindElementsByClass("pagination__item").Count
    Application.Wait Now + TimeValue("00:00:02")


    'To click the close button of the popup
    bot.FindElementByXPath("//*[@id='react-component-InfoSessionsPopup']/div/div/div[1]").Click


    bot.Quit

End Sub

使用 Selenium VBA 關閉此彈出窗口的任何幫助將不勝感激

要關閉打開鏈接時顯示的彈出窗口,您可以使用以下任一定位器策略

  • 使用FindElementByCss()

     bot.FindElementByCss("div.webinar-popup__close").Click
  • 使用FindElementByXPath()

     bot.FindElementByXPath("//div[@class='webinar-popup__close']").Click

我會等到 javascript 被 Selenium 完全加載,然后使用宏或 RPA 工具(如 Approbotic)使用 X/Y 屏幕坐標單擊關閉按鈕。 這樣的事情應該適合你:

Public Sub scrapeCIL2()
    Dim bot As New WebDriver, btn As Object, i As Long, pageCount As Long
    Set x = CreateObject("AppRobotic.API")
    Dim wins As Variant



    bot.Start "chrome", "https://duproprio.com/en/search/list?search=true&regions%5B0%5D=6&is_for_sale=1&with_builders=1&parent=1&pageNumber=2&sort=-published_at"
    bot.Get "/"
    pageCount = bot.FindElementsByClass("pagination__item").Count
    Application.Wait Now + TimeValue("00:00:02")


    'To click the close button of the popup
    'bot.FindElementByXPath("//*[@id='react-component-InfoSessionsPopup']/div/div/div[1]").Click
    'Move the mouse to X/Y coordinates after looking up popup coordinates with UI Item Explorer
    Call x.MoveCursor(500,500) :
    'Wait one second
    x.Wait(1000) :
    'Click the popup close button
    x.MouseLeftClick() :

    bot.Quit

End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM