![](/img/trans.png)
[英]How to disable opening the page in a new tab in Selenium Webdriver in Python?
[英]How to fix Selenium Webdriver not opening a new tab on Firefox 68.0 and above?
升級到 firefox 68 后,我的 selenium python 腳本損壞了,我無法使用之前工作的代碼打開新選項卡。
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
my_profile = webdriver.FirefoxProfile()
my_profile.set_preference("browser.tabs.remote.autostart", False)
my_profile.set_preference("browser.tabs.remote.autostart.1", False)
my_profile.set_preference("browser.tabs.remote.autostart.2", False)
browser = webdriver.Firefox(firefox_profile=my_profile)
browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')
事實證明,Mozilla 從 Firefox 68 開始對未來的 Firefox 版本進行了更改,
因此將“browser.tabs.remote.autostart”值更改為false,根本不會禁用e10s(多進程)
因此不會在 selenium 中打開一個新選項卡。
你可以在這里讀更多關於它的內容:
https://techdows.com/2019/05/mozilla-firefox-68-doesnt-allow-turning-off-e10s.html
https://www.ghacks.net/2016/07/22/multi-process-firefox/
解決辦法是刪除之前的代碼,改用這個:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import os
os.environ['MOZ_FORCE_DISABLE_E10S'] = '1'
browser = webdriver.Firefox()
browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.