Selenium Bot: Windows 的不规则切换

Selenium Bot: Irregular Switching of Windows

单击元素 更多信息 后,link 被单击,然后 window 跳回到之前的 window 并且显示 TimeoutException

代码:

self.driver.window_handles
        base = "https://outlook.office.com/mail/inbox/id/AAQkADQ0ZmY1YmRkLWExNDEtNGNlYS1iOTZmLTVmNzNjMzhkNjUyMgAQAJmE%2FyrhD0supMphUUSGrmQ%3D"
        window_set = {self.driver.window_handles[0], self.driver.window_handles[1]}

        for x in window_set:
            if(base != x):
                self.driver.maximize_window()
                wait = WebDriverWait(self.driver, 10)
                self.driver.switch_to.window(x)
                frame = wait.until(EC.presence_of_element_located((By.NAME, "mainFrame")))
                self.driver.switch_to.frame(frame)
                element = wait.until(EC.element_to_be_clickable((By.ID, "mc-lnk-moreInfo")))
                element.click()

帮助

网页图片:(包含两个标签)

在此图像中 更多信息 已单击并更改为 较少信息

成功了!

self.driver.window_handles
        wait = WebDriverWait(self.driver, 10)
        base = self.driver.window_handles[0]
        child = self.driver.window_handles[1]
        windows = {self.driver.window_handles[0], self.driver.window_handles[1]}

        for x in windows:
            if(base != x):
                self.driver.switch_to.window(x)
                frame = wait.until(EC.presence_of_element_located((By.NAME, "mainFrame")))
                self.driver.switch_to.frame(frame)
                element = wait.until(EC.element_to_be_clickable((By.ID, "mc-lnk-moreInfo")))
                element.click()