selenium+unittest 成功登录之后 获取到的url还是登录页面的url

如题,这是我写的登录脚本

    @file_data('zentao_login.yaml')
    def test_login(self, user, pwd, status):
        account = user
        password = pwd
        # 元素定位:分别是用户名输入框、密码输入框、登录按钮
        user_loc = self.driver.find_element(By.XPATH, '//*[@id="account"]')
        pwd_loc = self.driver.find_element(By.XPATH, '//*[@id="login-form"]/form/table/tbody/tr[2]/td/input')
        btn_loc = self.driver.find_element(By.XPATH, '//*[@id="submit"]')

        # 判断状态: 0为正确用户名密码 1为不正确用户名密码
        if status == '0':
            # 给元素传值
            user_loc.send_keys(account)
            pwd_loc.send_keys(password)
            # 点击登录
            btn_loc.click()
            print(self.driver.title, self.driver.current_url)
            self.assertEqual('my', self.driver.current_url)
            self.assertIn('我的地盘', self.driver.title)
        elif status == '1':
            # 给元素传值
            user_loc.send_keys(account)
            pwd_loc.send_keys(password)
            # 点击登录
            btn_loc.click()
            print(self.driver.title, self.driver.current_url)
            # print(self.driver.switch_to.alert.text)
            self.driver.switch_to.alert.accept()
            sleep(3)
        else:
            print('参数化的状态只能传入01')

这是执行后的结果:

img

img

两个问题:
一、为什么成功登录之后(执行过程中已经看到登录之后的页面了而且能看到页面的url也是登录之后的url),获取到的URL还是登录页面的URL
二、上图2的Error为啥会报错?下图是错误用户名密码登录后弹出的警告框

img

current_window = self.driver.current_window_handle # 定位下当前窗口

self.driver.switch_to.window(window) # 切换下试试

现在很奇怪的一件事情就是:我给他单独写了这两种情况,单独执行的时候都没问题!不管是弹窗的处理 还是登录后的url 都是正确的。。

img