[英]Opening a new unfocused tab in Chrome or Firefox with Python on Windows OS
[英]Opening a new tab with undetected chrome driver python
我試圖在 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')")
您可以嘗試使用--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/')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.