Python + selenium webdriver等待弹出窗口

时间:2015-02-12 14:37:38

标签: python selenium popup wait unit-testing

执行自动测试后,它会崩溃,导致弹出窗口出现约20秒。我需要等到弹出窗口加载并关闭它。如果您启动以下代码,则可以看到弹出窗口。

import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

    class FixInside(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Firefox()

    def test_login_tensor(self):
        driver = self.driver
        driver.get("https://fix-inside.tensor.ru")
        driver.maximize_window()
        self.assertIn("Вход в систему/СБиС", driver.title)
        element = driver.find_element_by_id('fld-loginName')
        element.send_keys('check_rigth_user')
        element = driver.find_element_by_id('fld-loginPass')
        element.send_keys('qwerty123')
        login = driver.find_element_by_id('logButton')
        login.click()
        wait = WebDriverWait(driver, 10)
        element = wait.until(EC.presence_of_element_located('ws-fixed ws-window shadow radius ws-modal ws-window-draggable'))
        close_popup = driver.find_element_by_class_name('ws-window-titlebar-action close')
        close_popup.click()

1 个答案:

答案 0 :(得分:0)

看来你的问题就在这一行:

element = wait.until(EC.presence_of_element_located(
    'ws-fixed ws-window shadow radius ws-modal ws-window-draggable'))

应该是:

element = wait.until(EC.presence_of_element_located((By.CLASS_NAME, 
    'ws-fixed ws-window shadow radius ws-modal ws-window-draggable')))

使用导入行:

from selenium.webdriver.common.by import By