球baba的欢乐时光

vuePress-theme-reco 球baba    2020 - 2025
球baba的欢乐时光 球baba的欢乐时光

Choose mode

  • dark
  • auto
  • light
Home
Category
  • 伪技术宅
Tag
TimeLine
Contact
  • reco_luan大大的NPM
  • reco_luan大大的GitHub
author-avatar

球baba

27

文章

58

标签

Home
Category
  • 伪技术宅
Tag
TimeLine
Contact
  • reco_luan大大的NPM
  • reco_luan大大的GitHub
  • chrome升级到107后selenium异常

chrome升级到107后selenium异常

vuePress-theme-reco 球baba    2020 - 2025

chrome升级到107后selenium异常


球baba 2022-11-28 21:55:00 chrome selenium

由于chrome一直自动升级,每次升级后程序运行都会报个chromedriver版本不支持的错,也就习以为常了。

但这次从105升级到107大版本后就有个很奇怪的问题,使用如下代码进行tab页切换,直到找到域名匹配的tab页

# 切换chrome至指定域名的tab页
def switch_to_target_page(PageUrl: str, chrome_port: str):
    options = webdriver.ChromeOptions()
    options.add_experimental_option(
        "debuggerAddress", "127.0.0.1:"+chrome_port)
    driver = webdriver.Chrome(options=options)

    target_url = PageUrl
    target_url_validate = 0

    for window_handle in driver.window_handles:
        driver.switch_to.window(window_handle)
        page_url = driver.current_url
        if(urlparse(driver.current_url).netloc == target_url):
            target_url_validate = 1
            break

    if(target_url_validate == 0):
        return False
    else:
        return True
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

第一次切换后,在选中的tab页上执行的操作没有问题。但切换到另一个tab页时,chrome确实是激活了所需的tab页,但selenium的模拟操作还是在第一次切换的标签页上,以为是函数中没有driver.quit()导致chrome升级版本后出现问题,但加了也不行。网上找了个104版本的安装包进行chrome降版后,就正常了,估计要么是chrome 107版本有什么新特性或者是chromedriver的bug了。

为了一劳永逸的解决chrome自动升级的问题,在网上找了个hosts屏蔽升级的方法:禁止谷歌浏览器 Google Chrome 自动更新的方法(实测有效) ,希望有用🙏


🌻🌻🌻