【问题标题】:Opening a new tab with undetected chrome driver python使用未检测到的 chrome 驱动程序 python 打开一个新选项卡
【发布时间】:2022-09-22 21:52:57
【问题描述】:

我试图在 python 中使用未检测到的 chrome 驱动程序打开另一个选项卡。我发现当我使用 javascript 方式时,chrome 会阻止我的弹出窗口。我无法弄清楚我做错了什么。这是我的代码。

options = webdriver.ChromeOptions()
options.add_argument(\'--disable-popup-blocking\')
if __name__ == \'__main__\':
      chrome = uc.Chrome(options=options)  
      time.sleep(1)
      chrome.get(\"https://www.google.com\")
      chrome.execute_script(\"window.open(\'https://google.com\',\'_blank\')\")

    标签: python selenium selenium-chromedriver undetected-chromedriver


    【解决方案1】:

    您可以尝试使用--disable-popup-blocking启用弹出窗口的参数。请参阅下面的代码示例

    from selenium.webdriver.chrome.options import Options
    import undetected_chromedriver as uc
    opts = Options()
    opts.add_argument('--disable-popup-blocking')
    driver = uc.Chrome(options=opts)
    driver.execute_script("window.open('about:blank', 'tab2');")
    driver.switch_to.window("tab2")  # or use driver.window_handles[-1] to get last opened tab
    driver.get('https://example.com/')
    

    【讨论】:

      猜你喜欢
      • 2020-03-09
      • 2017-12-30
      • 1970-01-01
      • 1970-01-01
      • 2019-11-22
      • 2016-07-31
      • 1970-01-01
      • 2014-01-10
      • 2012-09-26
      相关资源
      最近更新 更多