簡體   English   中英

Selenium 問題 - 彈出窗口

[英]Issue with Selenium - Pop Up window

有時有彈出窗口但有時不出現時如何放置條件。

    try{  
        WebDriverWait wait = new WebDriverWait(driver, 5);
        wait.until(ExpectedConditions.alertIsPresent());
        System.out.println(driver.switchTo().alert().getText());
        driver.switchTo().alert();  
    }     
    catch (NoAlertPresentException Ex)  
    {
        System.out.println("No alert");
    }

嘗試以下

from selenium import webdriver
from selenium.common.exceptions import NoAlertPresentException


def example():
    firefox_browser = webdriver.Firefox(executable_path=r'geckodriver.exe')
    firefox_browser.get('https://www.google.com')

    """check if alert is displayed
    """
    try:
        alert = firefox_browser.switch_to.alert
    except NoAlertPresentException:
        print("No alert")
        return False
    else:
        return True


if __name__ == "__main__":
    example()

暫無
暫無

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

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