linux Installation browser and driver
Firefox Browser - Comes with CentOS 6.10, and the browser version is 52
Download the corresponding Firefox driver, version 52 - version 0.17- View Address
Add to environment variables
# decompression tar -zxvf geckodriver-v0.17.0-linux64.tar.gz # New folder mkdir /usr/local/seleniumdriver # Move to folder mv geckodriver /usr/local/seleniumdriver # Edit/ect/profile file vim /etc/profile # Add at the end of the file export PATH=$PATH:/usr/local/seleniumdriver # Save Exit Run source /etc/profile # Run geckodriver-V geckodriver 0.17.0
Note: The best way to run the project is to put it in the English catalogue.
Firefox defaults to version 60
Using 0.19 Firefox driver, extract and save in / usr/local/seleciumdriver folder
Add to / etc/profile file
# Editing documents vim /etc/profile # Browser Driver export PATH=$PATH:/usr/local/seleniumdriver # Save Exit Run source /etc/profile # Run geckodriver-V geckodriver 0.19.0
At runtime, you can view the error by generating the geckodriver.log file from the current directory
Run directly with root user: python 123.py
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status: 1
Point: This can be found by looking at geckodriver.log:
1565086641745 geckodriver INFO geckodriver 0.19.0 1565086641748 geckodriver INFO Listening on 127.0.0.1:56020 1565086641834 mozrunner::runner INFO Running command: "/usr/lib64/firefox/firefox" "-marionette" "-profile" "/tmp/rust_mozprofile.3LBcykrEU73V" Running Firefox as root in a regular user's session is not supported. ($XDG_RUNTIME_DIR is /run/user/1000 which is owned by admin.)
The above error does not support running Firefox as root in an ordinary user's session. Solution: Switch to other users to execute.
import time from selenium import webdriver driver = webdriver.Firefox() driver.get("http://www.baidu.com") time.sleep(3) driver.quit()
It's okay to run directly on the remote server, but to report errors when running remotely on win10 pycharm:
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
Two problems: 1. Unable to find Firefox driver 2. When using remote connection (such as using pycharm or other connection tool xshell), it is default to connect linux without interface, which causes it to be unable to start. You can modify the code as follows:
import time from selenium import webdriver # Set to headless mode profile = webdriver.FirefoxOptions() profile.add_argument("-headless") # Designated Firefox Directory driver =webdriver.Firefox(executable_path="/usr/local/seleniumdriver/geckodriver",options=profile) driver.get("http://www.baidu.com") print(driver.page_source) time.sleep(3) driver.quit()
Emphasis 1: It is found that deploying test projects to linux servers with interfaces requires adding headless patterns and specifying driver locations.
Emphasis 2: There is an interface linux in VM. After login, it doesn't need to run directly (adding headless mode and specifying driver location). So you can connect the linux desktop with win, and then execute the code.
Emphasis 3: Originally deployed with interface servers, in order to run in the server, while the operation of the interface is more in line with expectations, so try to combine jenkins operation, is to operate with local users.
- download Google Browser Download
- Download the file named rpm End Installation Package - google-chrome-stable_current_x86_64.rpm
- Enter the command to install yum localinstall google-chrome-stable_current_x86_64.rpm
- The installed version is: Google Chrome 76.0.3809.87 (official version) (64 bits)
- Install the driver, as in the previous step, find the corresponding version for decompression, and place it in the / usr/local/seleciumdriver folder
- Refresh permission source/etc/profile
- Verify chromedriver --version
- Run the code.