gpt4 book ai didi

Python Selenium : How to close the tab that gets open automatically along with the tab that selenium opens

转载 作者:行者123 更新时间:2023-12-01 02:54:11 24 4
gpt4 key购买 nike

在打开所需的网址之前,我在 chromedriver 上安装了 chrome 扩展。安装扩展程序后,它会打开一个选项卡,其中提到“感谢您安装”。

扩展网址:https://chrome.google.com/webstore/detail/buyhatke/jaehkpjddfdgiiefcnhahapilbejohhj?hl=en

我想关闭扩展程序打开的选项卡,因为它不必要地加载数据。

代码片段:

from selenium import webdriver
import time
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from bs4 import BeautifulSoup as soup

chrome_options = Options()
chrome_options.add_argument('load-
extension=C:\\Users\\SACHIN\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Extensions\\jaehkpjddfdgiiefcnhahapilbejohhj\\3.4.141_0')

driver = webdriver.Chrome(chrome_options=chrome_options)
driver.implicitly_wait(30)

driver.get("https://paytm.com/shop/p/samsung-j3-pro-16-gb-black-MOBSAMSUNG-J3-PSTPL5914255C1B4E1C?src=grid&tracker=curated%7C%7Cmobile%20phones%7CCategory%20Grid%7C%2Fg%2Fmobile-accessories%2Fmobiles%2Fsmart-phones%7C66781%7C1%7C")

最佳答案

您可以切换到标签页

window_before = driver.window_handles[0] // May be 1 in your case 
driver.switch_to_window(window_before)

并关闭驱动程序。

或者发送 Alt + Tab 键并关闭选项卡

关于Python Selenium : How to close the tab that gets open automatically along with the tab that selenium opens,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44394167/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com