zoukankan      html  css  js  c++  java
  • selenium多窗口切换

    selenium操作中,会通过click()操作,打开新窗口。当需要操作新窗口时,就需要进行窗口切换。

    (1)JS执行click操作

    # 解决报错(Other element would receive the click)

    organization = self.driver.find_element(By.XPATH, '//span[contains(text(), "%s")]' % organization_name)
    # 定位到元素Arguments传参:arguments[0],传入organization的第一个参数
    self.driver.execute_script("$(arguments[0]).click()", organization)

    (2)窗口切换

    # 导入包文件

    from selenium.webdriver.support.wait import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC

    from selenium.webdriver.common.by import By

    # 获取当前窗口句柄
    current = self.driver.current_window_handle
    # 获取当前所有的窗口句柄
    handles = self.driver.window_handles
    # 预览审批流程按钮点击:弹出新窗口
    self.driver.find_element(By.XPATH, '//*[@id="basicInfo"]/div[1]/div/a').click()
    # 等待新窗口打开
    WebDriverWait(self.driver, 10).until(EC.new_window_is_opened(handles))
    # 切换到新窗口
    self.driver.switch_to.window([w for w in self.driver.window_handles if w != current][0])
    # 关闭新窗口
    self.driver.close()
    # 回到旧窗口
    self.driver.switch_to.window(current)

  • 相关阅读:
    压测 正则 性能分析
    时间复杂度 根号n
    务端如何防止重复支付 架构文摘 2021-05-02
    工具大于约定和文档
    千亿级公司低代码平台的测试体系介绍
    疑惑 题解
    计算几何相关总结
    树 题解
    矩阵加速相关总结
    loj6274 数字 题解
  • 原文地址:https://www.cnblogs.com/String-song/p/14484322.html
Copyright © 2011-2022 走看看