Firefox下載地址
Firefox全歷史版本下載:
http://ftp.mozilla.org/pub/firefox/releases/
Firefox驅動問題下載 https://github.com/mozilla/geckodriver/releases
我本地測試用的驅動版本:geckodriver-v0.30.0-win64.zip
我本地測試用的火狐版本:92.0
我本地測試用的操作系統:centos7
火狐瀏覽器解壓安裝出現的問題
下載火狐版本包,上傳,解壓(tar jxf)執行命令報錯如下:
問題一: [machangwei@xxx ~]$ ./firefox/firefox XPCOMGlueLoad error for file /home/machangwei/firefox/libmozgtk.so: libgtk-3.so.0: cannot open shared object file: No such file or directory Couldn't load XPCOM. 問題二: [deployer@xxx firefox]$ ./firefox XPCOMGlueLoad error for file /apps/svr/firefox/libxul.so: libXt.so.6: cannot open shared object file: No such file or directory Couldn't load XPCOM.
問題復現及解決
問題一復現及解決:
問題一缺少gtk3,執行如下命令解決
yum install -y gtk3
如果還不行,把gtk2也裝上,回頭補充詳情
[root@localhost ~]# rpm -qa|egrep "gtk2|gtk3" gtk2-2.24.31-1.el7.x86_64 gtk3-3.22.30-6.el7.x86_64 [root@localhost ~]# yum remove gtk3 Loaded plugins: fastestmirror Resolving Dependencies --> Running transaction check ---> Package gtk3.x86_64 0:3.22.30-6.el7 will be erased --> Processing Dependency: libgdk-3.so.0()(64bit) for package: google-chrome-stable-88.0.4324.150-1.x86_64 --> Processing Dependency: libgtk-3.so.0()(64bit) for package: google-chrome-stable-88.0.4324.150-1.x86_64 --> Running transaction check ---> Package google-chrome-stable.x86_64 0:88.0.4324.150-1 will be erased --> Finished Dependency Resolution Dependencies Resolved ===================================================================================================== Package Arch Version Repository Size ============================================================================================= Removing: gtk3 x86_64 3.22.30-6.el7 @updates 17 M Removing for dependencies: google-chrome-stable x86_64 88.0.4324.150-1 installed 228 M Transaction Summary ========================================================== Remove 1 Package (+1 Dependent package) Installed size: 245 M Is this ok [y/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Erasing : google-chrome-stable-88.0.4324.150-1.x86_64 1/2 Erasing : gtk3-3.22.30-6.el7.x86_64 2/2 Verifying : gtk3-3.22.30-6.el7.x86_64 1/2 Verifying : google-chrome-stable-88.0.4324.150-1.x86_64 2/2 Removed: gtk3.x86_64 0:3.22.30-6.el7 Dependency Removed: google-chrome-stable.x86_64 0:88.0.4324.150-1 Complete! [root@localhost ~]# ./firefox/firefox XPCOMGlueLoad error for file /root/firefox/libmozgtk.so: libgtk-3.so.0: cannot open shared object file: No such file or directory Couldn't load XPCOM. [root@localhost ~]# yum install -y gtk3 Loaded plugins: fastestmirror base | 3.6 kB 00:00:00 epel | 4.7 kB 00:00:00 extras | 2.9 kB 00:00:00 google-chrome | 1.3 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/4): google-chrome/primary | 1.8 kB 00:00:00 (2/4): epel/x86_64/updateinfo | 1.0 MB 00:00:00 (3/4): epel/x86_64/primary_db | 7.0 MB 00:00:15 (4/4): updates/7/x86_64/primary_db | 12 MB 00:00:29 Determining fastest mirrors * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com google-chrome 3/3 Resolving Dependencies --> Running transaction check ---> Package gtk3.x86_64 0:3.22.30-6.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved 。。。。。。。 Install 1 Package Total download size: 4.4 M Installed size: 17 M Downloading packages: gtk3-3.22.30-6.el7.x86_64.rpm | 4.4 MB 00:00:12 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : gtk3-3.22.30-6.el7.x86_64 1/1 Verifying : gtk3-3.22.30-6.el7.x86_64 1/1 Installed: gtk3.x86_64 0:3.22.30-6.el7 Complete! [root@localhost ~]# rpm -qa|grep chrome #原有的谷歌被卸載了,其實谷歌有用,並不想卸載呢,所有yum卸載連依賴一起卸載很危險,需要怎么解決這個 問題 [root@localhost ~]# [root@localhost ~]# ./firefox/firefox [GFX1-]: glxtest: libEGL initialize failed [GFX1-]: glxtest: X error, error_code=2, request_code=148, minor_code=3 [GFX1-]: glxtest: process failed (exited with status 1)
卸載之后報錯,重裝gtk3之后成功啟動火狐瀏覽器
卸載了gtk2之后還是能啟動火狐的,重新啟動進程頁面就正常加載出來
卸載gtk3,谷歌瀏覽器被當做依賴誤卸載掉
重裝谷歌
谷歌還是能正常使用的
問題二復現及解決:
移除libXt文件,問題復現,重新yum安裝,問題解決
[root@localhost ~]# ./firefox/firefox >/dev/null 2>&1 & [1] 9310 [root@localhost ~]# ps -ef|grep firefox root 9310 9294 48 09:13 pts/6 00:00:11 ./firefox/firefox root 9437 9310 9 09:13 pts/6 00:00:01 /root/firefox/firefox-bin -contentproc -childID 1 -isForBrowser -prefsLen 1 -prefMapSize 248973 -jsInit 285716 -parentBuildID 20210901125518 -appdir /root/firefox/browser 9310 true tab root 9488 9310 6 09:13 pts/6 00:00:00 /root/firefox/firefox-bin -contentproc -childID 2 -isForBrowser -prefsLen 160 -prefMapSize 248973 -jsInit 285716 -parentBuildID 20210901125518 -appdir /root/firefox/browser 9310 true tab root 9524 9310 6 09:13 pts/6 00:00:00 /root/firefox/firefox-bin -contentproc -childID 4 -isForBrowser -prefsLen 5583 -prefMapSize 248973 -jsInit 285716 -parentBuildID 20210901125518 -appdir /root/firefox/browser 9310 true tab root 9541 9294 0 09:13 pts/6 00:00:00 grep --color=auto firefox [root@localhost ~]# rpm -qa|grep libXt libXtst-1.2.3-1.el7.x86_64 libXt-1.1.5-3.el7.x86_64 yum remove libXt-1.1.5-3.el7.x86_64 Removed: libXt.x86_64 0:1.1.5-3.el7 Dependency Removed: dbus-x11.x86_64 1:1.10.24-15.el7 firefox.x86_64 0:78.14.0-1.el7.centos libXaw.x86_64 0:1.0.13-4.el7 libXmu.x86_64 0:1.1.2-2.el7 xorg-x11-server-utils.x86_64 0:7.7-20.el7 xorg-x11-xauth.x86_64 1:1.0.9-1.el7 xorg-x11-xinit.x86_64 0:1.3.4-2.el7 xterm.x86_64 0:295-3.el7_9.1 [root@localhost ~]# ./firefox/firefox XPCOMGlueLoad error for file /root/firefox/libxul.so: libXt.so.6: cannot open shared object file: No such file or directory Couldn't load XPCOM. [root@localhost ~]# yum install -y libXt-1.1.5-3.el7.x86_64 Running transaction Installing : libXt-1.1.5-3.el7.x86_64 1/1 Verifying : libXt-1.1.5-3.el7.x86_64 1/1 Installed: libXt.x86_64 0:1.1.5-3.el7 [root@localhost ~]# ./firefox/firefox Error: no DISPLAY environment variable specified [root@localhost ~]# yum install -y xorg-x11-server-utils.x86_64 xorg-x11-xinit.x86_64 Installed: xorg-x11-server-utils.x86_64 0:7.7-20.el7 xorg-x11-xinit.x86_64 0:1.3.4-2.el7 Dependency Installed: libXmu.x86_64 0:1.1.2-2.el7 xorg-x11-xauth.x86_64 1:1.0.9-1.el7 [root@localhost ~]# ./firefox/firefox Error: no DISPLAY environment variable specified [root@localhost ~]# eval `dbus-launch --sh-syntax` -bash: dbus-launch: command not found [root@localhost ~]# yum install -y dbus-x11.x86_64 [root@localhost ~]# eval `dbus-launch --sh-syntax` [root@localhost ~]# ./firefox/firefox Error: no DISPLAY environment variable specified
重新打開一個會話窗口,成功啟動進程
[root@localhost ~]# ./firefox/firefox >/dev/null 2>&1 & [1] 2333 [root@localhost ~]# ps -ef|grep firefox root 2333 1891 22 10:40 pts/2 00:00:04 ./firefox/firefox root 2484 2333 6 10:40 pts/2 00:00:01 /root/firefox/firefox-bin -contentproc -childID 1 -isForBrowser -prefsLen 1 -prefMapSize 249090 -jsInit 285716 -parentBuildID 20210901125518 -appdir /root/firefox/browser 2333 true tab root 2536 2333 0 10:40 pts/2 00:00:00 /root/firefox/firefox-bin -contentproc -childID 2 -isForBrowser -prefsLen 96 -prefMapSize 249090 -jsInit 285716 -parentBuildID 20210901125518 -appdir /root/firefox/browser 2333 true tab root 2601 2333 5 10:40 pts/2 00:00:00 /root/firefox/firefox-bin -contentproc -childID 4 -isForBrowser -prefsLen 5590 -prefMapSize 249090 -jsInit 285716 -parentBuildID 20210901125518 -appdir /root/firefox/browser 2333 true tab root 2665 2333 2 10:40 pts/2 00:00:00 /root/firefox/firefox-bin -contentproc -parentBuildID 20210901125518 -prefsLen 5590 -prefMapSize 249090 -appdir /root/firefox/browser 2333 true rdd root 2718 1891 0 10:40 pts/2 00:00:00 grep --color=auto firefox
需要安裝的libXt依賴包總結:
libXt.x86_64 dbus-x11.x86_64 firefox.x86_64 libXaw.x86_64 libXmu.x86_64
xorg-x11-server-utils.x86_64 xorg-x11-xauth xorg-x11-xinit.x86_64 xterm.x86_64
[machangwei@aocxxx ~]$ rpm -qa|grep "libXt|dbus-x11|libXaw|libXmu|xorg-x11-server-utils|xorg-x11-xauth|xorg-x11-xinit|xterm"
[machangwei@aocxxx ~]$
firefox
問題3解決亂碼:
Centos Firefox中文亂碼(對Centos7/8都有效) yum -y groupinstall Fonts 馬上生效。 查看是否安裝成功
下載依賴包到本地:
yum install --downloadonly --downloaddir=/root/mcw/prob1 libXt dbus-x11 libXaw libXmu dbus-x11 xorg-x11-server-utils xorg-x11-xauth xorg-x11-xinit xterm
yum groupinstall --downloadonly --downloaddir=/root/mcw/language Fonts
功能測試
windows上打開linux版瀏覽器測試,正常訪問
windows上啟用linux版火狐,需要安裝圖形化界面,安裝xmanger,xshell啟用xmanager
linux火狐能正常訪問
python程序測試火狐瀏覽器是否能正常使用
#from selenium.webdriver.chrome.options import Options
from selenium.webdriver.firefox.options import Options
from time import sleep
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('/root/firefox/firefox')
# 創建一個參數對象,用來控制chrome以無界面模式打開
chrome_options = Options()
#chrome_options.add_argument('--headless') #無頭瀏覽器
#chrome_options.add_argument('--disable-gpu')
#chrome_options.add_argument('--no-sandbox')
#chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--headless')
chrome_options.add_argument('blink-settings=imagesEnabled=false')
chrome_options.add_argument('--disable-gpu')
print("111111111111111111111")
#實例化一個瀏覽器對象
#bro = webdriver.Chrome(executable_path='/root/chromedriver',chrome_options=chrome_options)
#bro = webdriver.Firefox(executable_path='/root/geckodriver',firefox_options=chrome_options)
bro = webdriver.Firefox(executable_path='/root/geckodriver',firefox_options=chrome_options,firefox_binary=binary) #實例化火狐瀏覽器對象。指定瀏覽器啟動文件firefox_binary位置,指定瀏覽器驅動位置executable_path,指定啟動參數,firefox_options
print("22222222222222222222222222222222")
bro.get('https://www.baidu.com')
print("33333333333333333333333333")
sleep(2)
bro.save_screenshot('1.png')
print("4444444444444444444444444444444444444444")
print(bro.page_source)
sleep(1)
bro.quit()
執行程序,成功截圖訪問百度的頁面
啟動Linux版火狐瀏覽器,需要使用xmanger連接(4a登錄的主機無法使用xmanager連接),支持圖形化界面才能啟動成功,並且在自己筆記本上打開圖形化的linux火狐瀏覽器。
之前進入了一個誤區,安裝了軟件就需要啟動。自動化測試只需要使用無頭瀏覽器來調用火狐,啟動火狐進程。所以無需安裝圖形化界面等,只需要解決火狐的缺少的庫文件,中文字符之類的問題,就可以使用程序測試是否能正常使用瀏覽器。
文檔整理不全,可參考筆記信息:
yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
yum install -y http://archives.fedoraproject.org/pub/archive/epel/6/x86_64/epel-release-6-8.noarch.rpm
#wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
#rpm -Uvh epel-release--.noarch.rpm
http://archives.fedoraproject.org/pub/archive/epel/
https://npm.taobao.org/mirrors/chromium-browser-snapshots/Win_x64/884014/
https://download.csdn.net/download/qq_40949759/11593946
啟動命令,火狐啟動后出來火狐瀏覽器中文亂碼
./firefox/firefox >/dev/null 2>&1 &
/opt/google/chrome/google-chrome --disable-setuid-sandbox --user-data-dir --no-sandbox
/opt/google/chrome/google-chrome --disable-setuid-sandbox --user-data-dir --no-sandbox >/dev/null 2>&1 &
說明dbus沒有建立,要安裝必要的工具:
# apt-get install dbus-x11
運行 dbus-launch :
# dbus-launch
1.啟動Chrome
/usr/bin/google-chrome
會報錯:
[31560:31560:0207/085601.085852:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
修改 /usr/bin/google-chrome文件
將 exec -a "$0" "$HERE/chrome" "$@" 改為
exec -a "$0" "$HERE/chrome" "$@" --user-data-dir --no-sandbox
就可以直接啟動了
Ubuntu
鏈接:https://www.jianshu.com/p/ea9a1a4ab95c
xmanager使用
https://blog.csdn.net/yongwan5637/article/details/84060709
xmanager安裝
https://www.xshellcn.com/xiazai.html
啟動程序
https://blog.csdn.net/longgeaisisi/article/details/90519690
安裝x11
https://blog.csdn.net/h106140873/article/details/107135811
安裝xterm,xterm出來小窗口
https://www.jianshu.com/p/23ba123ee874
2.在服務器端vi /etc/ssh/sshd_config,添加一行:需要root,不確定是否開啟了的
X11Forwarding yes
dbus命令沒有
dbus-x11 yum安裝
centos6的源
https://developer.aliyun.com/mirror/
epel 6的源
http://archives.fedoraproject.org/pub/archive/epel/
yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
yum install -y http://archives.fedoraproject.org/pub/archive/epel/6/x86_64/epel-release-6-8.noarch.rpm